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
WavefrontCommandAccount, WavefrontCommandAlert, WavefrontCommandApitoken, WavefrontCommandCloudintegration, WavefrontCommandConfig, WavefrontCommandDashboard, WavefrontCommandDerivedmetric, WavefrontCommandEvent, WavefrontCommandIngestionpolicy, WavefrontCommandIntegration, WavefrontCommandLink, WavefrontCommandMessage, WavefrontCommandMetric, WavefrontCommandMetricspolicy, WavefrontCommandNotificant, WavefrontCommandProxy, WavefrontCommandQuery, WavefrontCommandRole, WavefrontCommandSavedsearch, WavefrontCommandServiceaccount, WavefrontCommandSettings, WavefrontCommandSource, WavefrontCommandSpy, WavefrontCommandUsage, 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.
- #description ⇒ Object
-
#docopt ⇒ String
A full options string which docopt understands.
- #global_option_text(width, term_width) ⇒ Object
-
#global_options ⇒ Array
All commands have these options.
-
#opt_row(opt_str, 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
The options the command understands.
-
#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.
- #thing ⇒ Object
- #things ⇒ Object
-
#word ⇒ String
The command keyword.
Instance Method Details
#_commands ⇒ Array
Inheriting classes must override this method
68 69 70 |
# File 'lib/wavefront-cli/commands/base.rb', line 68 def _commands [] end |
#_options ⇒ Array
Inheriting classes must override this method
39 40 41 |
# File 'lib/wavefront-cli/commands/base.rb', line 39 def [] end |
#acl_commands ⇒ Array
Anything which takes ACLs provides the same interface
58 59 60 61 62 63 |
# File 'lib/wavefront-cli/commands/base.rb', line 58 def acl_commands ["acls #{CMN} <id>", "acl #{CMN} clear <id>", "acl #{CMN} grant (view | modify) on <id> to <name>...", "acl #{CMN} revoke (view | modify) on <id> from <name>..."] end |
#commands(term_width = TW) ⇒ String
Returns the subcommands the command offers.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/wavefront-cli/commands/base.rb', line 104 def commands(term_width = TW) text_arr = %w[Usage:] _commands.flatten.each do |cmd| folded = "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width) text_arr << " #{folded}" end text_arr << " #{CMD} #{word} --help" text_arr.join("\n") end |
#common_options ⇒ Array
Many commands have these options
31 32 33 34 |
# File 'lib/wavefront-cli/commands/base.rb', line 31 def ['-E, --endpoint=URI Wavefront cluster endpoint', '-t, --token=TOKEN Wavefront authentication token'] end |
#description ⇒ Object
10 11 12 |
# File 'lib/wavefront-cli/commands/base.rb', line 10 def description "view and manage #{things}" end |
#docopt ⇒ String
Returns a full options string which docopt understands.
170 171 172 |
# File 'lib/wavefront-cli/commands/base.rb', line 170 def docopt "#{commands}\n\n#{}\n\n#{postscript}" end |
#global_option_text(width, term_width) ⇒ Object
133 134 135 136 137 |
# File 'lib/wavefront-cli/commands/base.rb', line 133 def global_option_text(width, term_width) text_arr = ['Global options:'] .each { |o| text_arr << opt_row(o, width, term_width) } text_arr << '' end |
#global_options ⇒ Array
All commands have these options
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wavefront-cli/commands/base.rb', line 17 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', '-f, --format=STRING output format', '-M, --items-only only show items in machine-parseable formats', '-h, --help show this message'] end |
#opt_row(opt_str, width, term_width = TW) ⇒ Object
Formats an option string.
rubocop:disable Lint/FormatParameterMismatch
147 148 149 150 |
# File 'lib/wavefront-cli/commands/base.rb', line 147 def opt_row(opt_str, width, term_width = TW) format(" %s %-#{width}s %s", *opt_str.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.
156 157 158 159 160 |
# File 'lib/wavefront-cli/commands/base.rb', line 156 def option_column_width ( + ).flatten.map do |o| o.split(/\s+/, 3)[0..1].join(' ').size end.max end |
#options(term_width = TW) ⇒ String
Returns the options the command understands.
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/wavefront-cli/commands/base.rb', line 120 def (term_width = TW) width = option_column_width text_arr = if .empty? [] else global_option_text(width, term_width) end text_arr << 'Options:' .flatten.each { |o| text_arr << opt_row(o, width, term_width) } text_arr.join("\n") end |
#postscript ⇒ String
Returns which will be printed underneath the options.
164 165 166 |
# File 'lib/wavefront-cli/commands/base.rb', line 164 def postscript '' end |
#sdk_class ⇒ String
Returns the name of the SDK class which does the work for this command.
89 90 91 |
# File 'lib/wavefront-cli/commands/base.rb', line 89 def sdk_class word.capitalize end |
#sdk_file ⇒ String
Returns the name of the SDK file which does the work for this command.
96 97 98 |
# File 'lib/wavefront-cli/commands/base.rb', line 96 def sdk_file word end |
#tag_commands ⇒ Array
Anything which takes tags provides the same interface
46 47 48 49 50 51 52 53 |
# File 'lib/wavefront-cli/commands/base.rb', line 46 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>", "tag pathsearch #{CMN} [-al] [-o offset] [-L limit] <word>"] end |
#thing ⇒ Object
78 79 80 |
# File 'lib/wavefront-cli/commands/base.rb', line 78 def thing word end |
#things ⇒ Object
82 83 84 |
# File 'lib/wavefront-cli/commands/base.rb', line 82 def things "#{thing}s" end |
#word ⇒ String
Returns the command keyword.
74 75 76 |
# File 'lib/wavefront-cli/commands/base.rb', line 74 def word self.class.name.sub('WavefrontCommand', '').downcase end |