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
  # Define the cloud integration command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the Configure command
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the dashboard command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the derivedmetric command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the event command.
@@ -20,7 +22,7 @@ class WavefrontCommandEvent < WavefrontCommandBase
20
22
  "wrap #{CMN} [-C command] [-d description] [-S severity] [-T type] " \
21
23
  '[-H host...] [-g tag...] <event>',
22
24
  tag_commands,
23
- 'show [-D]']
25
+ "show #{CMN}"]
24
26
  end
25
27
 
26
28
  def _options
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the integration command.
@@ -18,7 +20,6 @@ class WavefrontCommandIntegration < WavefrontCommandBase
18
20
  "alert install #{CMN} <id>",
19
21
  "alert uninstall #{CMN} <id>",
20
22
  "installed #{CMN}",
21
- "manifests #{CMN}",
22
23
  "search #{CMN} [-al] [-o offset] [-L limit] <condition>..."]
23
24
  end
24
25
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the external link command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the message command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the metric command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the notificant command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the proxy command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the query command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the saved search command.
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ # Define the service account command.
6
+ #
7
+ class WavefrontCommandServiceaccount < WavefrontCommandBase
8
+ def thing
9
+ 'service account'
10
+ end
11
+
12
+ def sdk_file
13
+ 'serviceaccount'
14
+ end
15
+
16
+ def sdk_class
17
+ 'ServiceAccount'
18
+ end
19
+
20
+ def _commands
21
+ ["list #{CMN} [-l] [-O fields]",
22
+ "describe #{CMN} <id>",
23
+ "create #{CMN} [-I] [-d description] [-m permission...] [-g group...] " \
24
+ '[-k usertoken...] <id>',
25
+ "activate #{CMN} <id>",
26
+ "deactivate #{CMN} <id>",
27
+ "dump #{CMN}",
28
+ "groups #{CMN} <id>",
29
+ "privileges #{CMN} <id>",
30
+ "join #{CMN} <id> <group>...",
31
+ "leave #{CMN} <id> <group>...",
32
+ "grant #{CMN} <privilege> to <id>",
33
+ "revoke #{CMN} <privilege> from <id>",
34
+ "set #{CMN} <key=value> <id>",
35
+ "import #{CMN} [-u] <file>",
36
+ "apitoken list #{CMN} [-O fields] <id>",
37
+ "apitoken create #{CMN} [-N name] <id>",
38
+ "apitoken delete #{CMN} <id> <token_id>",
39
+ "apitoken rename #{CMN} <id> <token_id> <name>",
40
+ "search #{CMN} [-al] [-o offset] [-L limit] <condition>..."]
41
+ end
42
+
43
+ def _options
44
+ [common_options,
45
+ "-l, --long list #{things} in detail",
46
+ "-a, --all list all #{things}",
47
+ "-o, --offset=n start from nth #{thing}",
48
+ "-L, --limit=COUNT number of #{things} to list",
49
+ '-O, --fields=F1,F2,... only show given fields',
50
+ "-u, --update update an existing #{thing}",
51
+ "-I, --inactive create an inactive #{thing}",
52
+ "-d, --desc=STRING description of #{thing}",
53
+ "-m, --permission=STRING give #{thing} this permission",
54
+ "-g, --group=STRING add #{thing} to this user group",
55
+ '-N, --name=STRING name of token',
56
+ '-k, --usertoken=STRING API token']
57
+ end
58
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the settings command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the source command.
@@ -13,7 +15,7 @@ class WavefrontCommandSource < WavefrontCommandBase
13
15
  "description set #{CMN} <id> <description>",
14
16
  "description clear #{CMN} <id>",
15
17
  "clear #{CMN} <id>",
16
- "search #{CMN} [-o offset] [-L limit] [-l] <condition>...",
18
+ "search #{CMN} [-al] [-o cursor] [-L limit] <condition>...",
17
19
  tag_commands]
18
20
  end
19
21
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the user command.
@@ -16,11 +18,11 @@ class WavefrontCommandUser < WavefrontCommandBase
16
18
  "describe #{CMN} <id>",
17
19
  "create #{CMN} [-e] [-m permission...] [-g group...] <id>",
18
20
  "invite #{CMN} [-m permission...] [-g group...] <id>",
19
- "set #{CMN} <key=value> <id>",
20
21
  "delete #{CMN} <user>...",
21
22
  "dump #{CMN}",
22
23
  "import #{CMN} [-u] <file>",
23
24
  "groups #{CMN} <id>",
25
+ "privileges #{CMN} <id>",
24
26
  "join #{CMN} <id> <group>...",
25
27
  "leave #{CMN} <id> <group>...",
26
28
  "grant #{CMN} <privilege> to <id>",
@@ -31,6 +33,7 @@ class WavefrontCommandUser < WavefrontCommandBase
31
33
  def _options
32
34
  [common_options,
33
35
  "-l, --long list #{things} in detail",
36
+ "-a, --all list all #{things}",
34
37
  "-o, --offset=n start from nth #{thing}",
35
38
  "-L, --limit=COUNT number of #{things} to list",
36
39
  '-O, --fields=F1,F2,... only show given fields',
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the usergroup command.
@@ -39,6 +41,7 @@ class WavefrontCommandUsergroup < WavefrontCommandBase
39
41
  def _options
40
42
  [common_options,
41
43
  "-l, --long list #{things} in detail",
44
+ "-a, --all list all #{things}",
42
45
  "-o, --offset=n start from nth #{thing}",
43
46
  "-L, --limit=COUNT number of #{things} to list",
44
47
  '-O, --fields=F1,F2,... only show given fields',
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the webhook command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the maintenance window command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  # Define the write command.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'inifile'
2
4
  require_relative 'exception'
3
5
  require_relative 'base'
@@ -32,7 +34,7 @@ module WavefrontCli
32
34
  test: proc { |v| %w[human json yaml].include?(v) } }
33
35
  ].freeze
34
36
 
35
- RX = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/
37
+ RX = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/.freeze
36
38
 
37
39
  def initialize(options)
38
40
  @options = options
@@ -57,11 +59,11 @@ module WavefrontCli
57
59
  require 'wavefront-sdk/defs/version'
58
60
  require_relative 'display/base'
59
61
 
60
- info = { 'wf version': WF_CLI_VERSION,
61
- 'wf path': CMD_PATH.realpath.to_s,
62
- 'SDK version': WF_SDK_VERSION,
63
- 'SDK location': WF_SDK_LOCATION.to_s,
64
- 'Ruby version': RUBY_VERSION,
62
+ info = { 'wf version': WF_CLI_VERSION,
63
+ 'wf path': CMD_PATH.realpath.to_s,
64
+ 'SDK version': WF_SDK_VERSION,
65
+ 'SDK location': WF_SDK_LOCATION.to_s,
66
+ 'Ruby version': RUBY_VERSION,
65
67
  'Ruby platform': Gem::Platform.local.os.capitalize }
66
68
 
67
69
  WavefrontDisplay::Base.new(info).long_output
@@ -90,11 +92,15 @@ module WavefrontCli
90
92
  def create_profile(profile)
91
93
  puts "Creating profile '#{profile}'."
92
94
 
93
- str = CONFIGURABLES.each_with_object("[#{profile}]") do |t, a|
94
- a.<< format("\n%s=%s", t[:key], read_thing(t))
95
+ prof_arr = ["[#{profile}]"]
96
+
97
+ CONFIGURABLES.each do |c|
98
+ prof_arr.<< format('%<key>s=%<value>s',
99
+ key: c[:key],
100
+ value: read_thing(c))
95
101
  end
96
102
 
97
- IniFile.new(content: str)
103
+ IniFile.new(content: prof_arr.join("\n"))
98
104
  end
99
105
 
100
106
  def do_delete
@@ -114,7 +120,9 @@ module WavefrontCli
114
120
 
115
121
  def do_envvars
116
122
  %w[WAVEFRONT_ENDPOINT WAVEFRONT_TOKEN WAVEFRONT_PROXY].each do |v|
117
- puts format('%-20s %s', v, ENV[v] || 'unset')
123
+ puts format('%-20<var>s %<value>s',
124
+ var: v,
125
+ value: ENV[v] || 'unset')
118
126
  end
119
127
  end
120
128
 
@@ -127,8 +135,8 @@ module WavefrontCli
127
135
  end
128
136
 
129
137
  def input_prompt(label, default)
130
- ret = format(' %s', label)
131
- ret.<< format(' [%s]', default) unless default.nil?
138
+ ret = format(' %<label>s', label: label)
139
+ ret.<< format(' [%<value>s]', value: default) unless default.nil?
132
140
  ret + ':> '
133
141
  end
134
142
 
@@ -152,15 +160,18 @@ module WavefrontCli
152
160
  def validate_input(input, default, test)
153
161
  if input.empty?
154
162
  raise WavefrontCli::Exception::MandatoryValue if default.nil?
163
+
155
164
  input = default
156
165
  end
157
166
 
158
167
  return input if test.call(input)
168
+
159
169
  raise WavefrontCli::Exception::InvalidValue
160
170
  end
161
171
 
162
172
  def present?
163
173
  return true if config_file.exist?
174
+
164
175
  raise WavefrontCli::Exception::ConfigFileNotFound, config_file
165
176
  end
166
177
 
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  module WavefrontCli
4
6
  # Universal truths
5
7
  #
6
8
  module Constants
7
- HUMAN_TIME_FORMAT = '%F %T'.freeze
8
- HUMAN_TIME_FORMAT_MS = '%F %T.%3N'.freeze
9
+ HUMAN_TIME_FORMAT = '%F %T'
10
+ HUMAN_TIME_FORMAT_MS = '%F %T.%3N'
9
11
 
10
12
  # The CLI will use these options if they are not supplied on the
11
13
  # command line or in a config file.
12
14
  #
13
15
  DEFAULT_OPTS = {
14
16
  endpoint: 'metrics.wavefront.com',
15
- format: :human
17
+ format: :human
16
18
  }.freeze
17
19
 
18
20
  # How many objects to get in each request when we are asked for
@@ -26,6 +28,10 @@ module WavefrontCli
26
28
 
27
29
  # Split regex for searches
28
30
  #
29
- SEARCH_SPLIT = /\^|!\^|=|!=|~|!~/
31
+ SEARCH_SPLIT = /\^|!\^|=|!=|~|!~/.freeze
32
+
33
+ # Where we store local event information
34
+ #
35
+ EVENT_STATE_DIR = Pathname.new('/var/tmp/wavefront')
30
36
  end
31
37
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # For development against a local checkout of the SDK, uncomment
2
4
  # this definition
3
5
  #
4
6
  # DEVELOPMENT = true
5
7
 
6
8
  if defined?(DEVELOPMENT)
7
- dir = Pathname.new(__FILE__).dirname.realpath.parent.parent.parent
9
+ dir = Pathname.new(__dir__).realpath.parent.parent.parent
8
10
  $LOAD_PATH.<< dir + 'lib'
9
11
  $LOAD_PATH.<< dir + 'wavefront-sdk' + 'lib'
10
12
  end
@@ -17,7 +19,7 @@ require_relative 'exception'
17
19
  require_relative 'opt_handler'
18
20
  require_relative 'stdlib/string'
19
21
 
20
- CMD_DIR = Pathname.new(__FILE__).dirname + 'commands'
22
+ CMD_DIR = Pathname.new(__dir__) + 'commands'
21
23
 
22
24
  # Dynamically generate a CLI interface from files which describe
23
25
  # each subcomand.
@@ -33,20 +35,36 @@ class WavefrontCliController
33
35
  @usage = docopt_hash
34
36
  cmd, opts = parse_args
35
37
  @opts = parse_opts(opts)
36
- cli_class_obj = load_cli_class(cmd, @opts)
38
+ cli_class_obj = cli_class(cmd, @opts)
37
39
  run_command(cli_class_obj)
38
40
  end
39
41
 
40
42
  # What you see when you do 'wf --help'
41
43
  # @return [String]
42
44
  #
45
+ # rubocop:disable Metrics/MethodLength
43
46
  def default_help
44
- s = "Wavefront CLI\n\nUsage:\n #{CMD} command [options]\n" \
45
- " #{CMD} --version\n #{CMD} --help\n\nCommands:\n"
47
+ s = ['Wavefront CLI',
48
+ '',
49
+ 'Usage:',
50
+ " #{CMD} command [options]",
51
+ " #{CMD} --version",
52
+ " #{CMD} --help",
53
+ '',
54
+ 'Commands:',
55
+ '']
56
+
57
+ cmds.sort.each do |k, v|
58
+ s.<< format(' %-18<command>s %<desc>s',
59
+ command: k,
60
+ desc: v.description)
61
+ end
46
62
 
47
- cmds.sort.each { |k, v| s.<< format(" %-18s %s\n", k, v.description) }
48
- s.<< "\nUse '#{CMD} <command> --help' for further information.\n"
63
+ s.<< ''
64
+ s.<< "Use '#{CMD} <command> --help' for further information."
65
+ s.join("\n")
49
66
  end
67
+ # rubocop:enable Metrics/MethodLength
50
68
 
51
69
  # @return [Hash] command descriptions for docopt.
52
70
  #
@@ -59,23 +77,25 @@ class WavefrontCliController
59
77
  # Parse the input. The first Docopt.docopt handles the default
60
78
  # options, the second works on the command.
61
79
  #
62
- # rubocop:disable Metrics/AbcSize
63
80
  def parse_args
64
81
  Docopt.docopt(usage[:default], version: WF_CLI_VERSION, argv: args)
65
82
  rescue Docopt::Exit => e
66
83
  cmd = args.empty? ? nil : args.first.to_sym
67
84
 
68
85
  abort e.message unless usage.key?(cmd)
86
+ parse_cmd(cmd)
87
+ end
69
88
 
70
- begin
71
- [cmd, sanitize_keys(Docopt.docopt(usage[cmd], argv: args))]
72
- rescue Docopt::DocoptLanguageError => e
73
- abort "Mangled command description:\n#{e.message}"
74
- rescue Docopt::Exit => e
75
- abort e.message
76
- end
89
+ # Parse a command.
90
+ # @param cmd [String] given command
91
+ #
92
+ def parse_cmd(cmd)
93
+ [cmd, sanitize_keys(Docopt.docopt(usage[cmd], argv: args))]
94
+ rescue Docopt::DocoptLanguageError => e
95
+ abort "Mangled command description:\n#{e.message}"
96
+ rescue Docopt::Exit => e
97
+ abort e.message
77
98
  end
78
- # rubocop:enable Metrics/AbcSize
79
99
 
80
100
  def parse_opts(options)
81
101
  WavefrontCli::OptHandler.new(options).opts
@@ -86,10 +106,8 @@ class WavefrontCliController
86
106
  # @param cmd [String]
87
107
  # @return WavefrontCli::cmd
88
108
  #
89
- # rubocop:disable Metrics/AbcSize
90
- def load_cli_class(cmd, opts)
91
- require_relative File.join('.', cmds[cmd].sdk_file)
92
- Object.const_get('WavefrontCli').const_get(cmds[cmd].sdk_class).new(opts)
109
+ def cli_class(cmd, opts)
110
+ load_cli_class(cmd, opts)
93
111
  rescue WavefrontCli::Exception::UnhandledCommand
94
112
  abort 'Fatal error. Unsupported command. Please open a Github issue.'
95
113
  rescue WavefrontCli::Exception::InvalidInput => e
@@ -97,10 +115,14 @@ class WavefrontCliController
97
115
  rescue RuntimeError => e
98
116
  abort "Unable to run command. #{e.message}."
99
117
  end
100
- # rubocop:enable Metrics/AbcSize
101
118
 
102
- # rubocop:disable Metrics/AbcSize
119
+ def load_cli_class(cmd, opts)
120
+ require_relative File.join('.', cmds[cmd].sdk_file)
121
+ Object.const_get('WavefrontCli').const_get(cmds[cmd].sdk_class).new(opts)
122
+ end
123
+
103
124
  # rubocop:disable Metrics/MethodLength
125
+ # rubocop:disable Metrics/AbcSize
104
126
  def run_command(cli_class_obj)
105
127
  cli_class_obj.validate_opts
106
128
  cli_class_obj.run
@@ -112,6 +134,10 @@ class WavefrontCliController
112
134
  handle_missing_credentials(e)
113
135
  rescue WavefrontCli::Exception::MandatoryValue
114
136
  abort 'A value must be supplied.'
137
+ rescue Wavefront::Exception::InvalidPermission => e
138
+ abort "'#{e}' is not a valid privilege."
139
+ rescue Wavefront::Exception::InvalidUserGroupId => e
140
+ abort "'#{e}' is not a valid user group id."
115
141
  rescue WavefrontCli::Exception::InvalidValue => e
116
142
  abort "Invalid value for #{e}."
117
143
  rescue WavefrontCli::Exception::ProfileExists => e
@@ -122,10 +148,14 @@ class WavefrontCliController
122
148
  abort 'File not found.'
123
149
  rescue WavefrontCli::Exception::InsufficientData => e
124
150
  abort "Insufficient data. #{e.message}"
151
+ rescue WavefrontCli::Exception::InvalidQuery => e
152
+ abort "Invalid query. API message: '#{e.message}'."
125
153
  rescue WavefrontCli::Exception::SystemError => e
126
154
  abort "Host system error. #{e.message}"
127
155
  rescue WavefrontCli::Exception::UnparseableInput => e
128
156
  abort "Cannot parse input. #{e.message}"
157
+ rescue WavefrontCli::Exception::UnparseableSearchPattern
158
+ abort 'Searches require a key, a value, and a match operator.'
129
159
  rescue WavefrontCli::Exception::UnsupportedFileFormat
130
160
  abort 'Unsupported file format.'
131
161
  rescue WavefrontCli::Exception::UnsupportedOperation => e
@@ -188,6 +218,7 @@ class WavefrontCliController
188
218
  #
189
219
  def import_command(path)
190
220
  return if path.extname != '.rb' || path.basename.to_s == 'base.rb'
221
+
191
222
  k_name = path.basename.to_s[0..-4]
192
223
  require(CMD_DIR + k_name)
193
224
  Object.const_get("WavefrontCommand#{k_name.capitalize}").new