Class: Dri::Command
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/dri/command.rb
Direct Known Subclasses
Dri::Commands::Add::FastQuarantine, Dri::Commands::Analyze::StackTraces, Dri::Commands::FAQ, Dri::Commands::Fetch::Failures, Dri::Commands::Fetch::FeatureFlags, Dri::Commands::Fetch::Pipelines, 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, Dri::Commands::View::FastQuarantine
Instance Method Summary
collapse
Constructor Details
#initialize(*options) ⇒ Command
Returns a new instance of Command.
18
19
20
|
# File 'lib/dri/command.rb', line 18
def initialize(*options)
@options = options
end
|
Instance Method Details
#add_color(str, *color) ⇒ Object
77
78
79
|
# File 'lib/dri/command.rb', line 77
def add_color(str, *color)
@options[:no_color] ? str : pastel.decorate(str, *color)
end
|
#api_client(ops: false) ⇒ Object
38
39
40
|
# File 'lib/dri/command.rb', line 38
def api_client(ops: false)
ApiClient.new(config, ops)
end
|
#bold(str) ⇒ Object
81
82
83
|
# File 'lib/dri/command.rb', line 81
def bold(str)
pastel.bold(str)
end
|
#command(**options) ⇒ Object
The external commands runner
110
111
112
113
|
# File 'lib/dri/command.rb', line 110
def command(**options)
require 'tty-command'
TTY::Command.new(**options)
end
|
#config ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dri/command.rb', line 27
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
120
121
122
123
|
# File 'lib/dri/command.rb', line 120
def cursor
require 'tty-cursor'
TTY::Cursor
end
|
#editor ⇒ Object
Open a file or text in the user’s preferred editor
130
131
132
133
|
# File 'lib/dri/command.rb', line 130
def editor
require 'tty-editor'
TTY::Editor
end
|
#emoji ⇒ Object
46
47
48
|
# File 'lib/dri/command.rb', line 46
def emoji
@emoji ||= profile["settings"]["emoji"]
end
|
#execute ⇒ Object
88
89
90
91
92
93
|
# File 'lib/dri/command.rb', line 88
def execute(*)
raise(
NotImplementedError,
"#{self.class}##{__method__} must be implemented"
)
end
|
#handover_report_path ⇒ Object
66
67
68
|
# File 'lib/dri/command.rb', line 66
def handover_report_path
@handover_report_path ||= profile["settings"]["handover_report_path"]
end
|
#logger ⇒ Object
95
96
97
98
|
# File 'lib/dri/command.rb', line 95
def logger
require 'tty-logger'
TTY::Logger.new
end
|
#ops_token ⇒ Object
58
59
60
|
# File 'lib/dri/command.rb', line 58
def ops_token
@ops_token ||= profile["settings"]["ops_token"]
end
|
#pastel(**options) ⇒ Object
22
23
24
|
# File 'lib/dri/command.rb', line 22
def pastel(**options)
Pastel.new(**options)
end
|
#profile ⇒ Object
42
43
44
|
# File 'lib/dri/command.rb', line 42
def profile
@profile ||= config.read
end
|
#prompt(**options) ⇒ Object
140
141
142
143
|
# File 'lib/dri/command.rb', line 140
def prompt(**options)
require 'tty-prompt'
TTY::Prompt.new(**options.merge(interrupt: :exit))
end
|
#spinner ⇒ Object
100
101
102
103
|
# File 'lib/dri/command.rb', line 100
def spinner
require 'tty-spinner'
TTY::Spinner.new("[:spinner] ⏳", format: :classic)
end
|
#timezone ⇒ Object
62
63
64
|
# File 'lib/dri/command.rb', line 62
def timezone
@timezone ||= profile["settings"]["timezone"]
end
|
#token ⇒ Object
54
55
56
|
# File 'lib/dri/command.rb', line 54
def token
@token ||= profile["settings"]["token"]
end
|
#username ⇒ Object
50
51
52
|
# File 'lib/dri/command.rb', line 50
def username
@username ||= profile["settings"]["user"]
end
|
#verify_config_exists ⇒ Object
70
71
72
73
74
75
|
# File 'lib/dri/command.rb', line 70
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
|