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, WavefrontCommandDashboard, WavefrontCommandEvent, WavefrontCommandIntegration, WavefrontCommandLink, WavefrontCommandMessage, WavefrontCommandMetric, WavefrontCommandProxy, WavefrontCommandQuery, WavefrontCommandSavedsearch, WavefrontCommandSource, WavefrontCommandUser, WavefrontCommandWebhook, WavefrontCommandWindow, WavefrontCommandWrite
Instance Method Summary collapse
- #column_widths ⇒ Object
-
#commands ⇒ Object
Returns a string describing the subcommands the command offers.
-
#common_options ⇒ Object
Many commands have these options.
-
#docopt ⇒ Object
Returns a full options string which docopt understands.
-
#global_options ⇒ Object
All commands have these options.
- #opt_row(opt, width) ⇒ Object
-
#options ⇒ Object
Returns a string describing the options the command understands.
-
#postscript ⇒ Object
Returns a string which will be printed underneath the options.
-
#sdk_class ⇒ Object
Returns the name of the SDK class which does the work for this command.
- #sdk_file ⇒ Object
-
#tag_commands ⇒ Object
Anything which takes tags provides the same interface.
-
#word ⇒ Object
The command keyword.
Instance Method Details
#column_widths ⇒ Object
74 75 76 77 78 |
# File 'lib/wavefront-cli/commands/base.rb', line 74 def column_widths ( + ).flatten.map do |o| o.split(/\s+/, 3)[0..1].join(' ').size end.max end |
#commands ⇒ Object
Returns a string describing the subcommands the command offers.
53 54 55 56 57 |
# File 'lib/wavefront-cli/commands/base.rb', line 53 def commands _commands.flatten.each_with_object("Usage:\n") do |cmd, ret| ret.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold + "\n" end + " #{CMD} #{word} --help" end |
#common_options ⇒ Object
Many commands have these options
19 20 21 22 |
# File 'lib/wavefront-cli/commands/base.rb', line 19 def ['-E, --endpoint=URI cluster endpoint', '-t, --token=TOKEN Wavefront authentication token'] end |
#docopt ⇒ Object
Returns a full options string which docopt understands
88 89 90 |
# File 'lib/wavefront-cli/commands/base.rb', line 88 def docopt commands + "\n\n" + + "\n" + postscript end |
#global_options ⇒ Object
All commands have these options
8 9 10 11 12 13 14 15 |
# File 'lib/wavefront-cli/commands/base.rb', line 8 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) ⇒ Object
70 71 72 |
# File 'lib/wavefront-cli/commands/base.rb', line 70 def opt_row(opt, width) format(" %s %-#{width}s %s\n", *opt.split(/\s+/, 3)) end |
#options ⇒ Object
Returns a string describing the options the command understands.
61 62 63 64 65 66 67 68 |
# File 'lib/wavefront-cli/commands/base.rb', line 61 def width = column_widths ret = "Global options:\n" .each { |o| ret.<< opt_row(o, width) } ret.<< "\nOptions:\n" .flatten.each { |o| ret.<< opt_row(o, width) } ret end |
#postscript ⇒ Object
Returns a string which will be printed underneath the options.
82 83 84 |
# File 'lib/wavefront-cli/commands/base.rb', line 82 def postscript '' end |
#sdk_class ⇒ Object
Returns the name of the SDK class which does the work for this command.
43 44 45 |
# File 'lib/wavefront-cli/commands/base.rb', line 43 def sdk_class word.capitalize end |
#sdk_file ⇒ Object
47 48 49 |
# File 'lib/wavefront-cli/commands/base.rb', line 47 def sdk_file word end |
#tag_commands ⇒ Object
Anything which takes tags provides the same interface
26 27 28 29 30 31 32 |
# File 'lib/wavefront-cli/commands/base.rb', line 26 def tag_commands ["tags #{CMN} [-f format] <id>", "tag set #{CMN} <id> <tag>...", "tag clear #{CMN} <id>", "tag add #{CMN} <id> <tag>", "tag delete #{CMN} <id> <tag>"] end |
#word ⇒ Object
The command keyword
36 37 38 |
# File 'lib/wavefront-cli/commands/base.rb', line 36 def word self.class.name.sub(/WavefrontCommand/, '').downcase end |