Class: Dri::Command
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/dri/command.rb
Direct Known Subclasses
Dri::Commands::Analyze::StackTraces, Dri::Commands::FAQ, Dri::Commands::Fetch::Failures, Dri::Commands::Fetch::FeatureFlags, Dri::Commands::Fetch::Pipelines, Dri::Commands::Fetch::Quarantines, Dri::Commands::Fetch::Runbooks, Dri::Commands::Fetch::Testcases, Dri::Commands::Fetch::Triaged, Dri::Commands::Incidents, Dri::Commands::Init, Dri::Commands::Profile, Dri::Commands::Publish::Report, Dri::Commands::Rm::Emoji, Dri::Commands::Rm::Profile, Dri::Commands::Rm::Reports
Instance Method Summary
collapse
Constructor Details
#initialize(*options) ⇒ Command
Returns a new instance of Command.
19
20
21
|
# File 'lib/dri/command.rb', line 19
def initialize(*options)
@options = options
end
|
Instance Method Details
#add_color(str, *color) ⇒ Object
78
79
80
|
# File 'lib/dri/command.rb', line 78
def add_color(str, *color)
@options[:no_color] ? str : pastel.decorate(str, *color)
end
|
#api_client(ops: false) ⇒ Object
39
40
41
|
# File 'lib/dri/command.rb', line 39
def api_client(ops: false)
ApiClient.new(config, ops)
end
|
#command(**options) ⇒ Object
The external commands runner
107
108
109
110
|
# File 'lib/dri/command.rb', line 107
def command(**options)
require 'tty-command'
TTY::Command.new(**options)
end
|
#config ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/dri/command.rb', line 28
def config
@config ||= begin
config = TTY::Config.new
config.filename = ".dri_profile"
config.extname = ".yml"
config.append_path Dir.home
config.append_path Dir.pwd
config
end
end
|
#cursor ⇒ Object
117
118
119
120
|
# File 'lib/dri/command.rb', line 117
def cursor
require 'tty-cursor'
TTY::Cursor
end
|
#editor ⇒ Object
Open a file or text in the user’s preferred editor
127
128
129
130
|
# File 'lib/dri/command.rb', line 127
def editor
require 'tty-editor'
TTY::Editor
end
|
#emoji ⇒ Object
47
48
49
|
# File 'lib/dri/command.rb', line 47
def emoji
@emoji ||= profile["settings"]["emoji"]
end
|
#execute ⇒ Object
85
86
87
88
89
90
|
# File 'lib/dri/command.rb', line 85
def execute(*)
raise(
NotImplementedError,
"#{self.class}##{__method__} must be implemented"
)
end
|
#handover_report_path ⇒ Object
67
68
69
|
# File 'lib/dri/command.rb', line 67
def handover_report_path
@handover_report_path ||= profile["settings"]["handover_report_path"]
end
|
#logger ⇒ Object
92
93
94
95
|
# File 'lib/dri/command.rb', line 92
def logger
require 'tty-logger'
TTY::Logger.new
end
|
#ops_token ⇒ Object
59
60
61
|
# File 'lib/dri/command.rb', line 59
def ops_token
@ops_token ||= profile["settings"]["ops_token"]
end
|
#pastel(**options) ⇒ Object
23
24
25
|
# File 'lib/dri/command.rb', line 23
def pastel(**options)
Pastel.new(**options)
end
|
#profile ⇒ Object
43
44
45
|
# File 'lib/dri/command.rb', line 43
def profile
@profile ||= config.read
end
|
#prompt(**options) ⇒ Object
137
138
139
140
|
# File 'lib/dri/command.rb', line 137
def prompt(**options)
require 'tty-prompt'
TTY::Prompt.new(**options.merge(interrupt: :exit))
end
|
#spinner ⇒ Object
97
98
99
100
|
# File 'lib/dri/command.rb', line 97
def spinner
require 'tty-spinner'
TTY::Spinner.new("[:spinner] ⏳", format: :classic)
end
|
#timezone ⇒ Object
63
64
65
|
# File 'lib/dri/command.rb', line 63
def timezone
@timezone ||= profile["settings"]["timezone"]
end
|
#token ⇒ Object
55
56
57
|
# File 'lib/dri/command.rb', line 55
def token
@token ||= profile["settings"]["token"]
end
|
#username ⇒ Object
51
52
53
|
# File 'lib/dri/command.rb', line 51
def username
@username ||= profile["settings"]["user"]
end
|
#verify_config_exists ⇒ Object
71
72
73
74
75
76
|
# File 'lib/dri/command.rb', line 71
def verify_config_exists
return if config.exist?
logger.error "Oops, could not find a configuration. Try using #{add_color('dri init', :yellow)} first."
exit 1
end
|