Class: WavefrontCommandBase
- Inherits:
-
Object
- Object
- WavefrontCommandBase
- Defined in:
- lib/wavefront-cli/commands/base.rb
Overview
A base class which all command classes extend.
Direct Known Subclasses
WavefrontCommandAlert, WavefrontCommandApitoken, WavefrontCommandCloudintegration, WavefrontCommandConfig, WavefrontCommandDashboard, WavefrontCommandDerivedmetric, WavefrontCommandEvent, WavefrontCommandIntegration, WavefrontCommandLink, WavefrontCommandMessage, WavefrontCommandMetric, WavefrontCommandNotificant, WavefrontCommandProxy, WavefrontCommandQuery, WavefrontCommandSavedsearch, WavefrontCommandSettings, WavefrontCommandSource, WavefrontCommandUser, WavefrontCommandUsergroup, WavefrontCommandWebhook, WavefrontCommandWindow, WavefrontCommandWrite
Instance Method Summary collapse
-
#_commands ⇒ Array
Inheriting classes must override this method.
-
#_options ⇒ Array
Inheriting classes must override this method.
-
#acl_commands ⇒ Array
Anything which takes ACLs provides the same interface.
-
#commands(term_width = TW) ⇒ String
The subcommands the command offers.
-
#common_options ⇒ Array
Many commands have these options.
-
#docopt ⇒ String
A full options string which docopt understands.
-
#global_options ⇒ Array
All commands have these options.
-
#opt_row(opt, width, term_width = TW) ⇒ Object
Formats an option string.
-
#option_column_width ⇒ Integer
The width of the column containing short and long options.
-
#options(term_width = TW) ⇒ String
rubocop:disable Metrics/AbcSize.
-
#postscript ⇒ String
Which will be printed underneath the options.
-
#sdk_class ⇒ String
The name of the SDK class which does the work for this command.
-
#sdk_file ⇒ String
The name of the SDK file which does the work for this command.
-
#tag_commands ⇒ Array
Anything which takes tags provides the same interface.
-
#word ⇒ String
The command keyword.
Instance Method Details
#_commands ⇒ Array
Inheriting classes must override this method
62 63 64 |
# File 'lib/wavefront-cli/commands/base.rb', line 62 def _commands [] end |
#_options ⇒ Array
Inheriting classes must override this method
32 33 34 |
# File 'lib/wavefront-cli/commands/base.rb', line 32 def [] end |
#acl_commands ⇒ Array
Anything which takes ACLs provides the same interface
50 51 52 53 54 55 56 57 |
# File 'lib/wavefront-cli/commands/base.rb', line 50 def acl_commands ["acls #{CMN} <id>", "acl #{CMN} clear <id>", "acl #{CMN} grant (view | modify) on <id> to " \ '(user | group) <name>...', "acl #{CMN} revoke (view | modify) on <id> from " \ '(user | group) <name>...'] end |
#commands(term_width = TW) ⇒ String
Returns the subcommands the command offers.
91 92 93 94 95 |
# File 'lib/wavefront-cli/commands/base.rb', line 91 def commands(term_width = TW) _commands.flatten.each_with_object("Usage:\n") do |cmd, ret| ret.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width) + "\n" end + " #{CMD} #{word} --help" end |
#common_options ⇒ Array
Many commands have these options
24 25 26 27 |
# File 'lib/wavefront-cli/commands/base.rb', line 24 def ['-E, --endpoint=URI cluster endpoint', '-t, --token=TOKEN Wavefront authentication token'] end |
#docopt ⇒ String
Returns a full options string which docopt understands.
147 148 149 |
# File 'lib/wavefront-cli/commands/base.rb', line 147 def docopt commands + "\n\n" + + "\n" + postscript end |
#global_options ⇒ Array
All commands have these options
12 13 14 15 16 17 18 19 |
# File 'lib/wavefront-cli/commands/base.rb', line 12 def ['-c, --config=FILE path to configuration file', '-P, --profile=NAME profile in configuration file', '-D, --debug enable debug mode', '-n, --noop do not perform API calls', '-V, --verbose be verbose', '-h, --help show this message'] end |
#opt_row(opt, width, term_width = TW) ⇒ Object
Formats an option string.
125 126 127 128 |
# File 'lib/wavefront-cli/commands/base.rb', line 125 def opt_row(opt, width, term_width = TW) format(" %s %-#{width}s %s\n", *opt.split(/\s+/, 3)) .opt_fold(term_width, width + 5) end |
#option_column_width ⇒ Integer
Returns the width of the column containing short and long options.
133 134 135 136 137 |
# File 'lib/wavefront-cli/commands/base.rb', line 133 def option_column_width ( + ).flatten.map do |o| o.split(/\s+/, 3)[0..1].join(' ').size end.max end |
#options(term_width = TW) ⇒ String
rubocop:disable Metrics/AbcSize
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/wavefront-cli/commands/base.rb', line 102 def (term_width = TW) width = option_column_width ret = '' unless .empty? ret.<< "Global options:\n" .each { |o| ret.<< opt_row(o, width, term_width) } ret.<< "\n" end ret.<< "Options:\n" .flatten.each { |o| ret.<< opt_row(o, width, term_width) } ret end |
#postscript ⇒ String
Returns which will be printed underneath the options.
141 142 143 |
# File 'lib/wavefront-cli/commands/base.rb', line 141 def postscript '' end |
#sdk_class ⇒ String
Returns the name of the SDK class which does the work for this command.
75 76 77 |
# File 'lib/wavefront-cli/commands/base.rb', line 75 def sdk_class word.capitalize end |
#sdk_file ⇒ String
Returns the name of the SDK file which does the work for this command.
82 83 84 |
# File 'lib/wavefront-cli/commands/base.rb', line 82 def sdk_file word end |
#tag_commands ⇒ Array
Anything which takes tags provides the same interface
39 40 41 42 43 44 45 |
# File 'lib/wavefront-cli/commands/base.rb', line 39 def tag_commands ["tags #{CMN} <id>", "tag set #{CMN} <id> <tag>...", "tag clear #{CMN} <id>", "tag add #{CMN} <id> <tag>", "tag delete #{CMN} <id> <tag>"] end |
#word ⇒ String
Returns the command keyword.
68 69 70 |
# File 'lib/wavefront-cli/commands/base.rb', line 68 def word self.class.name.sub(/WavefrontCommand/, '').downcase end |