Class: Sfctl::Command
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/sfctl/command.rb
Direct Known Subclasses
Sfctl::Commands::Account::Assignments, Sfctl::Commands::Account::Info, Sfctl::Commands::Auth::Bye, Sfctl::Commands::Auth::Init, Sfctl::Commands::Time::Connections::Add, Sfctl::Commands::Time::Connections::Get, Sfctl::Commands::Time::Init, Sfctl::Commands::Time::Providers::Get, Sfctl::Commands::Time::Providers::Set, Sfctl::Commands::Time::Providers::Unset, Sfctl::Commands::Time::Sync
Constant Summary
collapse
- CONFIG_FILENAME =
'.sfctl'
- CONFIG_PATH =
"#{Dir.home}/#{CONFIG_FILENAME}"
- LINK_CONFIG_FILENAME =
'.sflink'
- LINK_CONFIG_PATH =
"#{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_token ⇒ Object
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
|
#config ⇒ Object
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
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
|
#execute ⇒ Object
71
72
73
74
75
76
|
# File 'lib/sfctl/command.rb', line 71
def execute(*)
raise(
NotImplementedError,
"#{self.class}##{__method__} must be implemented"
)
end
|
#link_config_present?(output) ⇒ 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_config ⇒ Object
38
39
40
|
# File 'lib/sfctl/command.rb', line 38
def read_config
config.read(CONFIG_PATH, format: :yaml)
end
|
#read_link_config ⇒ Object
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
|
#save_link_config! ⇒ Object
57
58
59
|
# File 'lib/sfctl/command.rb', line 57
def save_link_config!
config.write(LINK_CONFIG_PATH, format: :yaml, force: true)
end
|