Class: Sfctl::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sfctl/command.rb

Constant Summary collapse

CONFIG_FILENAME =
'.sfctl'
CONFIG_PATH =
"#{Dir.home}/#{CONFIG_FILENAME}"
'.sflink'
"#{Dir.pwd}/#{LINK_CONFIG_FILENAME}"
TOGGL_PROVIDER =
'toggl'
HARVEST_PROVIDER =
'harvest'
PROVIDERS_LIST =
[
  TOGGL_PROVIDER,
  HARVEST_PROVIDER
].freeze

Instance Method Summary collapse

Instance Method Details

#access_tokenObject



42
43
44
# File 'lib/sfctl/command.rb', line 42

def access_token
  read_config['access_token']
end

#command(**options) ⇒ Object

The external commands runner



83
84
85
86
# File 'lib/sfctl/command.rb', line 83

def command(**options)
  require 'tty-command'
  TTY::Command.new(options)
end

#configObject

Main configuration



26
27
28
29
30
31
32
# File 'lib/sfctl/command.rb', line 26

def config
  @config ||= begin
    config = TTY::Config.new
    config.append_path Dir.home
    config
  end
end

#config_present?(output) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/sfctl/command.rb', line 46

def config_present?(output)
  read_config
rescue TTY::Config::ReadError
  output.puts Pastel.new(enabled: !@options['no-color']).red('Please authentificate before continue.')
  false
end

#executeObject

Execute this command

Raises:

  • (NotImplementedError)


71
72
73
74
75
76
# File 'lib/sfctl/command.rb', line 71

def execute(*)
  raise(
    NotImplementedError,
    "#{self.class}##{__method__} must be implemented"
  )
end

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/sfctl/command.rb', line 61

def link_config_present?(output)
  read_link_config
rescue TTY::Config::ReadError
  output.puts Pastel.new(enabled: !@options['no-color']).red('Please initialize time before continue.')
  false
end

#read_configObject



38
39
40
# File 'lib/sfctl/command.rb', line 38

def read_config
  config.read(CONFIG_PATH, format: :yaml)
end


53
54
55
# File 'lib/sfctl/command.rb', line 53

def read_link_config
  config.read(LINK_CONFIG_PATH, format: :yaml)
end

#save_config!Object



34
35
36
# File 'lib/sfctl/command.rb', line 34

def save_config!
  config.write(CONFIG_PATH, format: :yaml, force: true)
end


57
58
59
# File 'lib/sfctl/command.rb', line 57

def save_link_config!
  config.write(LINK_CONFIG_PATH, format: :yaml, force: true)
end