wavefront-cli 4.2.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.rubocop.yml +1 -14
  4. data/.travis.yml +4 -4
  5. data/Gemfile +2 -0
  6. data/HISTORY.md +82 -60
  7. data/Rakefile +2 -0
  8. data/bin/wf +1 -0
  9. data/lib/wavefront-cli/alert.rb +13 -5
  10. data/lib/wavefront-cli/apitoken.rb +2 -0
  11. data/lib/wavefront-cli/base.rb +95 -47
  12. data/lib/wavefront-cli/cloudintegration.rb +6 -0
  13. data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
  14. data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
  15. data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
  16. data/lib/wavefront-cli/commands/alert.rb +2 -1
  17. data/lib/wavefront-cli/commands/apitoken.rb +6 -0
  18. data/lib/wavefront-cli/commands/base.rb +30 -21
  19. data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
  20. data/lib/wavefront-cli/commands/config.rb +2 -0
  21. data/lib/wavefront-cli/commands/dashboard.rb +2 -0
  22. data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
  23. data/lib/wavefront-cli/commands/event.rb +3 -1
  24. data/lib/wavefront-cli/commands/integration.rb +2 -1
  25. data/lib/wavefront-cli/commands/link.rb +2 -0
  26. data/lib/wavefront-cli/commands/message.rb +2 -0
  27. data/lib/wavefront-cli/commands/metric.rb +2 -0
  28. data/lib/wavefront-cli/commands/notificant.rb +2 -0
  29. data/lib/wavefront-cli/commands/proxy.rb +2 -0
  30. data/lib/wavefront-cli/commands/query.rb +2 -0
  31. data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
  32. data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
  33. data/lib/wavefront-cli/commands/settings.rb +2 -0
  34. data/lib/wavefront-cli/commands/source.rb +3 -1
  35. data/lib/wavefront-cli/commands/user.rb +4 -1
  36. data/lib/wavefront-cli/commands/usergroup.rb +3 -0
  37. data/lib/wavefront-cli/commands/webhook.rb +2 -0
  38. data/lib/wavefront-cli/commands/window.rb +2 -0
  39. data/lib/wavefront-cli/commands/write.rb +2 -0
  40. data/lib/wavefront-cli/config.rb +23 -12
  41. data/lib/wavefront-cli/constants.rb +10 -4
  42. data/lib/wavefront-cli/controller.rb +53 -22
  43. data/lib/wavefront-cli/dashboard.rb +3 -0
  44. data/lib/wavefront-cli/derivedmetric.rb +12 -11
  45. data/lib/wavefront-cli/display/alert.rb +7 -4
  46. data/lib/wavefront-cli/display/apitoken.rb +2 -0
  47. data/lib/wavefront-cli/display/base.rb +34 -8
  48. data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
  49. data/lib/wavefront-cli/display/dashboard.rb +2 -0
  50. data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
  51. data/lib/wavefront-cli/display/distribution.rb +2 -0
  52. data/lib/wavefront-cli/display/event.rb +2 -0
  53. data/lib/wavefront-cli/display/externallink.rb +2 -0
  54. data/lib/wavefront-cli/display/integration.rb +2 -0
  55. data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
  56. data/lib/wavefront-cli/display/message.rb +7 -3
  57. data/lib/wavefront-cli/display/metric.rb +3 -1
  58. data/lib/wavefront-cli/display/notificant.rb +3 -1
  59. data/lib/wavefront-cli/display/printer/long.rb +36 -11
  60. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
  61. data/lib/wavefront-cli/display/printer/terse.rb +6 -1
  62. data/lib/wavefront-cli/display/proxy.rb +2 -0
  63. data/lib/wavefront-cli/display/query.rb +35 -24
  64. data/lib/wavefront-cli/display/savedsearch.rb +2 -0
  65. data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
  66. data/lib/wavefront-cli/display/settings.rb +2 -0
  67. data/lib/wavefront-cli/display/source.rb +18 -4
  68. data/lib/wavefront-cli/display/user.rb +56 -10
  69. data/lib/wavefront-cli/display/usergroup.rb +25 -19
  70. data/lib/wavefront-cli/display/webhook.rb +2 -0
  71. data/lib/wavefront-cli/display/write.rb +6 -2
  72. data/lib/wavefront-cli/event.rb +83 -62
  73. data/lib/wavefront-cli/exception.rb +3 -0
  74. data/lib/wavefront-cli/externallink.rb +6 -4
  75. data/lib/wavefront-cli/integration.rb +2 -0
  76. data/lib/wavefront-cli/maintenancewindow.rb +28 -17
  77. data/lib/wavefront-cli/message.rb +4 -0
  78. data/lib/wavefront-cli/metric.rb +4 -1
  79. data/lib/wavefront-cli/notificant.rb +2 -0
  80. data/lib/wavefront-cli/opt_handler.rb +2 -0
  81. data/lib/wavefront-cli/output/base.rb +8 -3
  82. data/lib/wavefront-cli/output/csv.rb +2 -0
  83. data/lib/wavefront-cli/output/csv/base.rb +2 -0
  84. data/lib/wavefront-cli/output/csv/query.rb +14 -7
  85. data/lib/wavefront-cli/output/hcl.rb +2 -0
  86. data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
  87. data/lib/wavefront-cli/output/hcl/base.rb +10 -4
  88. data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
  89. data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
  90. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
  91. data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
  92. data/lib/wavefront-cli/output/json.rb +2 -0
  93. data/lib/wavefront-cli/output/ruby.rb +2 -0
  94. data/lib/wavefront-cli/output/wavefront.rb +2 -0
  95. data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
  96. data/lib/wavefront-cli/output/yaml.rb +2 -0
  97. data/lib/wavefront-cli/proxy.rb +15 -3
  98. data/lib/wavefront-cli/query.rb +14 -12
  99. data/lib/wavefront-cli/savedsearch.rb +2 -0
  100. data/lib/wavefront-cli/serviceaccount.rb +179 -0
  101. data/lib/wavefront-cli/settings.rb +2 -0
  102. data/lib/wavefront-cli/source.rb +2 -0
  103. data/lib/wavefront-cli/stdlib/array.rb +3 -0
  104. data/lib/wavefront-cli/stdlib/string.rb +17 -11
  105. data/lib/wavefront-cli/user.rb +10 -4
  106. data/lib/wavefront-cli/usergroup.rb +4 -2
  107. data/lib/wavefront-cli/version.rb +3 -1
  108. data/lib/wavefront-cli/webhook.rb +2 -0
  109. data/lib/wavefront-cli/write.rb +80 -46
  110. data/spec/.rubocop.yml +3 -16
  111. data/spec/constants.rb +21 -0
  112. data/spec/spec_helper.rb +8 -422
  113. data/spec/support/command_base.rb +82 -0
  114. data/spec/support/minitest_assertions.rb +262 -0
  115. data/spec/support/output_tester.rb +32 -0
  116. data/spec/support/supported_commands.rb +19 -0
  117. data/spec/test_mixins/acl.rb +169 -0
  118. data/spec/test_mixins/delete.rb +25 -0
  119. data/spec/test_mixins/deleteundelete.rb +106 -0
  120. data/spec/test_mixins/describe.rb +24 -0
  121. data/spec/test_mixins/dump.rb +43 -0
  122. data/spec/test_mixins/general.rb +11 -0
  123. data/spec/test_mixins/history.rb +35 -0
  124. data/spec/test_mixins/import.rb +65 -0
  125. data/spec/test_mixins/list.rb +29 -0
  126. data/spec/test_mixins/search.rb +98 -0
  127. data/spec/test_mixins/set.rb +47 -0
  128. data/spec/test_mixins/tag.rb +99 -0
  129. data/spec/wavefront-cli/alert_spec.rb +288 -111
  130. data/spec/wavefront-cli/apitoken_spec.rb +53 -24
  131. data/spec/wavefront-cli/base_spec.rb +9 -27
  132. data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
  133. data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
  134. data/spec/wavefront-cli/commands/base_spec.rb +15 -13
  135. data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
  136. data/spec/wavefront-cli/commands/config_spec.rb +3 -0
  137. data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
  138. data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
  139. data/spec/wavefront-cli/commands/event_spec.rb +1 -0
  140. data/spec/wavefront-cli/commands/link_spec.rb +1 -0
  141. data/spec/wavefront-cli/commands/message_spec.rb +1 -0
  142. data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
  143. data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
  144. data/spec/wavefront-cli/commands/query_spec.rb +1 -0
  145. data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
  146. data/spec/wavefront-cli/commands/window_spec.rb +1 -0
  147. data/spec/wavefront-cli/commands/write_spec.rb +1 -0
  148. data/spec/wavefront-cli/config_spec.rb +25 -14
  149. data/spec/wavefront-cli/controller_spec.rb +13 -3
  150. data/spec/wavefront-cli/dashboard_spec.rb +125 -76
  151. data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
  152. data/spec/wavefront-cli/display/base_spec.rb +5 -7
  153. data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
  154. data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
  155. data/spec/wavefront-cli/event_spec.rb +360 -18
  156. data/spec/wavefront-cli/externallink_spec.rb +92 -58
  157. data/spec/wavefront-cli/integration_spec.rb +129 -31
  158. data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
  159. data/spec/wavefront-cli/message_spec.rb +73 -30
  160. data/spec/wavefront-cli/metric_spec.rb +60 -22
  161. data/spec/wavefront-cli/notificant_spec.rb +45 -32
  162. data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
  163. data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
  164. data/spec/wavefront-cli/output/csv_spec.rb +5 -2
  165. data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
  166. data/spec/wavefront-cli/output/helpers.rb +18 -0
  167. data/spec/wavefront-cli/output/json_spec.rb +3 -1
  168. data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
  169. data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
  170. data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
  171. data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
  172. data/spec/wavefront-cli/proxy_spec.rb +49 -27
  173. data/spec/wavefront-cli/query_spec.rb +174 -92
  174. data/spec/wavefront-cli/resources/responses/query.json +1 -0
  175. data/spec/wavefront-cli/resources/updates/alert.json +15 -0
  176. data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
  177. data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
  178. data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
  179. data/spec/wavefront-cli/settings_spec.rb +42 -11
  180. data/spec/wavefront-cli/source_spec.rb +120 -23
  181. data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
  182. data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
  183. data/spec/wavefront-cli/user_spec.rb +278 -108
  184. data/spec/wavefront-cli/usergroup_spec.rb +152 -102
  185. data/spec/wavefront-cli/webhook_spec.rb +30 -15
  186. data/spec/wavefront-cli/write_spec.rb +25 -1
  187. data/wavefront-cli.gemspec +5 -3
  188. metadata +65 -21
  189. data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
  190. data/spec/wavefront-cli/display/spec_helper.rb +0 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'json'
3
5
  require 'wavefront-sdk/validators'
@@ -91,7 +93,7 @@ module WavefrontCli
91
93
  def validate_input
92
94
  validate_id if options[:'<id>']
93
95
  validate_tags if options[:'<tag>']
94
- send(:extra_validation) if respond_to?(:extra_validation)
96
+ extra_validation if respond_to?(:extra_validation)
95
97
  end
96
98
 
97
99
  def validate_tags(key = :'<tag>')
@@ -112,7 +114,9 @@ module WavefrontCli
112
114
  end
113
115
 
114
116
  def failed_validation_message(input)
115
- format("'%s' is not a valid %s ID.", input, klass_word)
117
+ format("'%<value>s' is not a valid %<thing>s ID.",
118
+ value: input,
119
+ thing: klass_word)
116
120
  end
117
121
 
118
122
  # Make a wavefront-sdk credentials object from standard
@@ -121,9 +125,9 @@ module WavefrontCli
121
125
  # @return [Hash] containing `token` and `endpoint`.
122
126
  #
123
127
  def mk_creds
124
- { token: options[:token],
128
+ { token: options[:token],
125
129
  endpoint: options[:endpoint],
126
- agent: "wavefront-cli-#{WF_CLI_VERSION}" }
130
+ agent: "wavefront-cli-#{WF_CLI_VERSION}" }
127
131
  end
128
132
 
129
133
  # Make a common wavefront-sdk options object from standard CLI
@@ -133,8 +137,8 @@ module WavefrontCli
133
137
  # @return [Hash] containing `debug`, `verbose`, and `noop`.
134
138
  #
135
139
  def mk_opts
136
- ret = { debug: options[:debug],
137
- noop: options[:noop] }
140
+ ret = { debug: options[:debug],
141
+ noop: options[:noop] }
138
142
 
139
143
  ret[:verbose] = options[:noop] ? true : options[:verbose]
140
144
 
@@ -219,12 +223,14 @@ module WavefrontCli
219
223
  exit if options[:noop]
220
224
 
221
225
  check_response_blocks(data)
226
+ warning_message(data.status)
222
227
  status_error_handler(data, method)
223
228
  handle_response(data.response, format_var, method)
224
229
  end
225
230
 
226
231
  def status_error_handler(data, method)
227
232
  return if check_status(data.status)
233
+
228
234
  handle_error(method, data.status.code) if format_var == :human
229
235
  display_api_error(data.status)
230
236
  end
@@ -242,7 +248,7 @@ module WavefrontCli
242
248
  # @return System exit
243
249
  #
244
250
  def display_api_error(status)
245
- method = format('handle_errcode_%s', status.code).to_sym
251
+ method = format('handle_errcode_%<code>s', code: status.code).to_sym
246
252
 
247
253
  msg = if respond_to?(method)
248
254
  send(method, status)
@@ -250,8 +256,15 @@ module WavefrontCli
250
256
  status.message || 'No further information'
251
257
  end
252
258
 
253
- abort format('ERROR: API code %s. %s.', status.code,
254
- msg.chomp('.')).fold(TW, 7)
259
+ abort format('ERROR: API code %<code>s. %<message>s.',
260
+ code: status.code,
261
+ message: msg.chomp('.')).fold(TW, 7)
262
+ end
263
+
264
+ def warning_message(status)
265
+ return unless status.status.between?(201, 299)
266
+
267
+ puts format("API WARNING: '%<message>s'.", message: status.message)
255
268
  end
256
269
 
257
270
  def display_no_api_response(data, method)
@@ -279,20 +292,25 @@ module WavefrontCli
279
292
  end
280
293
  end
281
294
 
282
- # rubocop:disable Metrics/AbcSize
283
- def parseable_output(format, resp)
295
+ def parseable_output(output_format, resp)
284
296
  options[:class] = klass_word
285
297
  options[:hcl_fields] = hcl_fields
286
- require_relative File.join('output', format.to_s)
287
- oclass = Object.const_get(format('WavefrontOutput::%s',
288
- format.to_s.capitalize))
289
- oclass.new(resp, options).run
298
+ cli_output_class(output_format).new(resp, options).run
290
299
  rescue LoadError
291
300
  raise(WavefrontCli::Exception::UnsupportedOutput,
292
- format("The '%s' command does not support '%s' output.",
293
- options[:class], format))
301
+ unsupported_format_message(output_format))
302
+ end
303
+
304
+ def cli_output_class(output_format)
305
+ require_relative File.join('output', output_format.to_s)
306
+ Object.const_get(format('WavefrontOutput::%<class>s',
307
+ class: output_format.to_s.capitalize))
308
+ end
309
+
310
+ def unsupported_format_message(output_format)
311
+ format("The '%<command>s' command does not support '%<format>s' output.",
312
+ command: options[:class], format: output_format)
294
313
  end
295
- # rubocop:enable Metrics/AbcSize
296
314
 
297
315
  def hcl_fields
298
316
  []
@@ -311,13 +329,12 @@ module WavefrontCli
311
329
  #
312
330
  def validate_opts
313
331
  unless options[:token]
314
- raise(WavefrontCli::Exception::CredentialError,
315
- 'Missing API token.')
332
+ raise(WavefrontCli::Exception::CredentialError, 'Missing API token.')
316
333
  end
317
334
 
318
335
  return true if options[:endpoint]
319
- raise(WavefrontCli::Exception::CredentialError,
320
- 'Missing API endpoint.')
336
+
337
+ raise(WavefrontCli::Exception::CredentialError, 'Missing API endpoint.')
321
338
  end
322
339
 
323
340
  # Give it a path to a file (as a string) and it will return the
@@ -335,18 +352,22 @@ module WavefrontCli
335
352
  return load_from_stdin if path == '-'
336
353
 
337
354
  file = Pathname.new(path)
355
+ extname = file.extname.downcase
338
356
 
339
357
  raise WavefrontCli::Exception::FileNotFound unless file.exist?
340
358
 
341
- extname = file.extname.downcase
359
+ return load_json(file) if extname == '.json'
360
+ return load_yaml(file) if %w[.yaml .yml].include?(extname)
342
361
 
343
- if extname == '.json'
344
- JSON.parse(IO.read(file), symbolize_names: true)
345
- elsif %w[.yaml .yml].include?(extname)
346
- YAML.safe_load(IO.read(file), symbolize_names: true)
347
- else
348
- raise WavefrontCli::Exception::UnsupportedFileFormat
349
- end
362
+ raise WavefrontCli::Exception::UnsupportedFileFormat
363
+ end
364
+
365
+ def load_json(file)
366
+ JSON.parse(IO.read(file), symbolize_names: true)
367
+ end
368
+
369
+ def load_yaml(file)
370
+ YAML.safe_load(IO.read(file), symbolize_names: true)
350
371
  end
351
372
 
352
373
  # Read STDIN and return a Ruby object, assuming that STDIN is
@@ -389,20 +410,33 @@ module WavefrontCli
389
410
  wf.describe(options[:'<id>'])
390
411
  end
391
412
 
392
- # rubocop:disable Metrics/AbcSize
393
413
  def do_dump
394
- items = wf.list(ALL_PAGE_SIZE, :all).response.items
414
+ cannot_noop!
395
415
 
396
416
  if options[:format] == 'yaml'
397
- ok_exit items.to_yaml
417
+ ok_exit dump_yaml
398
418
  elsif options[:format] == 'json'
399
- ok_exit items.to_json
419
+ ok_exit dump_json
400
420
  else
401
- abort format("Dump format must be 'json' or 'yaml'. (Tried '%s')",
402
- options[:format])
421
+ abort format("Dump format must be 'json' or 'yaml'. " \
422
+ "(Tried '%<format>s')", options)
403
423
  end
404
424
  end
405
- # rubocop:enable Metrics/AbcSize
425
+
426
+ def dump_yaml
427
+ JSON.parse(item_dump_call.to_json).to_yaml
428
+ end
429
+
430
+ def dump_json
431
+ item_dump_call.to_json
432
+ end
433
+
434
+ # Broken out into its own method because 'users' does not use
435
+ # pagination
436
+ #
437
+ def item_dump_call
438
+ wf.list(ALL_PAGE_SIZE, :all).response.items
439
+ end
406
440
 
407
441
  def do_import
408
442
  raw = load_file(options[:'<file>'])
@@ -411,6 +445,7 @@ module WavefrontCli
411
445
  [raw].flatten.each do |obj|
412
446
  resp = import_object(obj)
413
447
  next if options[:noop]
448
+
414
449
  errs += 1 unless resp.ok?
415
450
  puts import_message(obj, resp)
416
451
  end
@@ -419,10 +454,10 @@ module WavefrontCli
419
454
  end
420
455
 
421
456
  def import_message(obj, resp)
422
- format('%-15s %-10s %s',
423
- obj[:id] || obj[:url],
424
- resp.ok? ? 'IMPORTED' : 'FAILED',
425
- resp.status.message)
457
+ format('%-15<id>s %-10<status>s %<message>s',
458
+ id: obj[:id] || obj[:url],
459
+ status: resp.ok? ? 'IMPORTED' : 'FAILED',
460
+ message: resp.status.message)
426
461
  end
427
462
 
428
463
  def import_object(raw)
@@ -456,7 +491,10 @@ module WavefrontCli
456
491
  def smart_delete_message(object_type)
457
492
  desc = wf.describe(options[:'<id>'])
458
493
  word = desc.ok? ? 'Soft' : 'Permanently'
459
- format("%s deleting %s '%s'", word, object_type, options[:'<id>'])
494
+ format("%<soft_or_hard>s deleting %<object>s '%<id>s'",
495
+ soft_or_hard: word,
496
+ object: object_type,
497
+ id: options[:'<id>'])
460
498
  end
461
499
 
462
500
  def do_undelete
@@ -479,17 +517,25 @@ module WavefrontCli
479
517
  # If the user has specified --all, override any limit and offset
480
518
  # values
481
519
  #
520
+ # rubocop:disable Metrics/MethodLength
482
521
  def range_hash
522
+ offset_key = :offset
523
+
483
524
  if options[:all]
484
525
  limit = :all
485
526
  offset = ALL_PAGE_SIZE
527
+ elsif options[:cursor]
528
+ offset_key = :cursor
529
+ limit = options[:limit]
530
+ offset = options[:cursor]
486
531
  else
487
532
  limit = options[:limit]
488
- offset = options[:offset] || options[:cursor]
533
+ offset = options[:offset]
489
534
  end
490
535
 
491
- { limit: limit, offset: offset }
536
+ { limit: limit, offset_key => offset }
492
537
  end
538
+ # rubocop:enable Metrics/MethodLength
493
539
 
494
540
  # The search URI pattern doesn't always match the command name,
495
541
  # or class name. Override this method if this is the case.
@@ -510,11 +556,11 @@ module WavefrontCli
510
556
  end
511
557
  end
512
558
 
513
- # rubocop:disable Metrics/CyclomaticComplexity
514
- # rubocop:disable Metrics/MethodLength
515
559
  # @param cond [String] a search condition, like "key=value"
516
560
  # @return [Hash] of matchingMethod and negated
517
561
  #
562
+ # rubocop:disable Metrics/CyclomaticComplexity
563
+ # rubocop:disable Metrics/MethodLength
518
564
  def matching_method(cond)
519
565
  case cond
520
566
  when /^\w+~/
@@ -533,8 +579,8 @@ module WavefrontCli
533
579
  raise(WavefrontCli::Exception::UnparseableSearchPattern, cond)
534
580
  end
535
581
  end
536
- # rubocop:enable Metrics/CyclomaticComplexity
537
582
  # rubocop:enable Metrics/MethodLength
583
+ # rubocop:enable Metrics/CyclomaticComplexity
538
584
 
539
585
  # Most things will re-import with the POST method if you remove
540
586
  # the ID.
@@ -579,6 +625,7 @@ module WavefrontCli
579
625
  # @param aggr [Array] values of matched keys
580
626
  # @return [Array]
581
627
  #
628
+ # rubocop:disable Metrics/MethodLength
582
629
  def extract_values(obj, key, aggr = [])
583
630
  if obj.is_a?(Hash)
584
631
  obj.each_pair do |k, v|
@@ -594,5 +641,6 @@ module WavefrontCli
594
641
 
595
642
  aggr
596
643
  end
644
+ # rubocop:enable Metrics/MethodLength
597
645
  end
598
646
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -9,6 +11,10 @@ module WavefrontCli
9
11
  Wavefront::Exception::InvalidCloudIntegrationId
10
12
  end
11
13
 
14
+ def do_delete
15
+ smart_delete('cloud integration')
16
+ end
17
+
12
18
  def do_enable
13
19
  wf.enable(options[:'<id>'])
14
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WavefrontCli
2
4
  module Mixin
3
5
  #
@@ -9,6 +11,7 @@ module WavefrontCli
9
11
  end
10
12
 
11
13
  def do_acl_clear
14
+ cannot_noop!
12
15
  wf.acl_set(options[:'<id>'], [], [everyone_id])
13
16
  do_acls
14
17
  end
@@ -66,7 +69,9 @@ module WavefrontCli
66
69
  def _acl_action(action)
67
70
  entity_type, entities = acl_entities
68
71
 
69
- resp = send(format('%s_%s', action, entity_type),
72
+ resp = send(format('%<action>s_%<type>s',
73
+ action: action,
74
+ type: entity_type),
70
75
  options[:'<id>'],
71
76
  entities)
72
77
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WavefrontCli
2
4
  module Mixin
3
5
  #
@@ -1,7 +1,6 @@
1
1
  ---
2
2
 
3
- inherit_from: ../../../.rubocop.yml
4
-
5
- # Some of these methods are long, but they're just lists
3
+ # There are long things in here, but they're fine
4
+ #
6
5
  Metrics/MethodLength:
7
- Enabled: false
6
+ Max: 25
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the Alert command
@@ -12,7 +14,6 @@ class WavefrontCommandAlert < WavefrontCommandBase
12
14
  "clone #{CMN} [-v version] <id>",
13
15
  "undelete #{CMN} <id>",
14
16
  "history #{CMN} [-o offset] [-L limit] <id>",
15
- "clone #{CMN} [-v version] <id>",
16
17
  "latest #{CMN} <id>",
17
18
  "dump #{CMN}",
18
19
  "import #{CMN} [-u] <file>",
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the apitoken command.
4
6
  #
5
7
  class WavefrontCommandApitoken < WavefrontCommandBase
8
+ def description
9
+ "view and your own #{things}"
10
+ end
11
+
6
12
  def thing
7
13
  'API token'
8
14
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../stdlib/string'
2
4
 
3
- CMN = '[-DnVM] [-c file] [-P profile] [-E endpoint] [-t token] ' \
4
- '[-f format]'.freeze
5
+ CMN = '[-DnVM] [-c file] [-P profile] [-E endpoint] [-t token] [-f format]'
5
6
 
6
7
  # A base class which all command classes extend.
7
8
  #
@@ -100,45 +101,53 @@ class WavefrontCommandBase
100
101
  # testing far simpler.
101
102
  # @return [String] the subcommands the command offers.
102
103
  #
103
- #
104
104
  def commands(term_width = TW)
105
- _commands.flatten.each_with_object("Usage:\n") do |cmd, ret|
106
- ret.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width) + "\n"
107
- end + " #{CMD} #{word} --help"
105
+ text_arr = %w[Usage:]
106
+
107
+ _commands.flatten.each do |cmd|
108
+ text_arr.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width)
109
+ end
110
+
111
+ text_arr.<< " #{CMD} #{word} --help"
112
+ text_arr.join("\n")
108
113
  end
109
114
 
110
115
  # @param term_width [Integer] force a terminal width. Makes
111
116
  # testing far simpler.
112
117
  # @return [String] the options the command understands.
113
118
  #
114
- # rubocop:disable Metrics/AbcSize
115
119
  def options(term_width = TW)
116
120
  width = option_column_width
117
- ret = ''
121
+ text_arr = if global_options.empty?
122
+ []
123
+ else
124
+ global_option_text(width, term_width)
125
+ end
118
126
 
119
- unless global_options.empty?
120
- ret.<< "Global options:\n"
121
- global_options.each { |o| ret.<< opt_row(o, width, term_width) }
122
- ret.<< "\n"
123
- end
127
+ text_arr.<< 'Options:'
128
+ _options.flatten.each { |o| text_arr.<< opt_row(o, width, term_width) }
129
+ text_arr.join("\n")
130
+ end
124
131
 
125
- ret.<< "Options:\n"
126
- _options.flatten.each { |o| ret.<< opt_row(o, width, term_width) }
127
- ret
132
+ def global_option_text(width, term_width)
133
+ text_arr = ['Global options:']
134
+ global_options.each { |o| text_arr.<< opt_row(o, width, term_width) }
135
+ text_arr.<< ''
128
136
  end
129
- # rubocop:enable Metrics/AbcSize
130
137
 
131
138
  # Formats an option string.
132
139
  #
133
- # @param opt [String] the option string
140
+ # @param opt_str [String] the option string
134
141
  # @param width [Integer] the width of the short + long options
135
142
  # columns. This is used to indent following lines
136
143
  # @param term_width [Integer] the width of the user's terminal
137
144
  #
138
- def opt_row(opt, width, term_width = TW)
139
- format(" %s %-#{width}s %s\n", *opt.split(/\s+/, 3))
140
- .opt_fold(term_width, width + 5)
145
+ # rubocop:disable Style/FormatStringToken
146
+ def opt_row(opt_str, width, term_width = TW)
147
+ format(" %s %-#{width}s %s",
148
+ *opt_str.split(/\s+/, 3)).opt_fold(term_width, width + 5)
141
149
  end
150
+ # rubocop:enable Style/FormatStringToken
142
151
 
143
152
  # @return [Integer] the width of the column containing short and
144
153
  # long options