wavefront-cli 8.5.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -4
  3. data/.github/workflows/test.yml +2 -2
  4. data/.rubocop.yml +1 -4
  5. data/Gemfile +10 -0
  6. data/HISTORY.md +17 -0
  7. data/README.md +4 -2
  8. data/lib/wavefront-cli/base.rb +4 -4
  9. data/lib/wavefront-cli/commands/base.rb +13 -10
  10. data/lib/wavefront-cli/commands/config.rb +3 -7
  11. data/lib/wavefront-cli/commands/derivedmetric.rb +1 -1
  12. data/lib/wavefront-cli/commands/metric.rb +3 -3
  13. data/lib/wavefront-cli/commands/metricspolicy.rb +33 -0
  14. data/lib/wavefront-cli/commands/query.rb +5 -5
  15. data/lib/wavefront-cli/commands/write.rb +12 -12
  16. data/lib/wavefront-cli/config.rb +31 -35
  17. data/lib/wavefront-cli/constants.rb +3 -2
  18. data/lib/wavefront-cli/controller.rb +19 -15
  19. data/lib/wavefront-cli/display/base.rb +2 -2
  20. data/lib/wavefront-cli/display/cluster.rb +21 -0
  21. data/lib/wavefront-cli/display/metricspolicy.rb +15 -0
  22. data/lib/wavefront-cli/display/printer/long.rb +11 -17
  23. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -3
  24. data/lib/wavefront-cli/display/query.rb +1 -1
  25. data/lib/wavefront-cli/display/write.rb +2 -1
  26. data/lib/wavefront-cli/event.rb +2 -2
  27. data/lib/wavefront-cli/exception_handler.rb +8 -1
  28. data/lib/wavefront-cli/helpers/load_file.rb +2 -2
  29. data/lib/wavefront-cli/maintenancewindow.rb +1 -1
  30. data/lib/wavefront-cli/metricspolicy.rb +42 -0
  31. data/lib/wavefront-cli/opt_handler.rb +2 -3
  32. data/lib/wavefront-cli/output/csv/query.rb +3 -3
  33. data/lib/wavefront-cli/output/hcl/base.rb +4 -4
  34. data/lib/wavefront-cli/output/hcl/dashboard.rb +7 -7
  35. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +1 -1
  36. data/lib/wavefront-cli/output/wavefront/query.rb +7 -7
  37. data/lib/wavefront-cli/stdlib/array.rb +1 -1
  38. data/lib/wavefront-cli/stdlib/string.rb +5 -5
  39. data/lib/wavefront-cli/usage.rb +1 -1
  40. data/lib/wavefront-cli/version.rb +1 -1
  41. data/lib/wavefront-cli/write.rb +15 -19
  42. data/spec/constants.rb +5 -6
  43. data/spec/support/command_base.rb +13 -1
  44. data/spec/support/minitest_assertions.rb +14 -10
  45. data/spec/support/output_tester.rb +2 -2
  46. data/spec/support/supported_commands.rb +3 -1
  47. data/spec/test_mixins/import.rb +2 -2
  48. data/spec/test_mixins/search.rb +9 -7
  49. data/spec/test_mixins/set.rb +1 -1
  50. data/spec/wavefront-cli/account_spec.rb +6 -4
  51. data/spec/wavefront-cli/alert_spec.rb +29 -6
  52. data/spec/wavefront-cli/base_spec.rb +1 -1
  53. data/spec/wavefront-cli/commands/base_spec.rb +3 -3
  54. data/spec/wavefront-cli/commands/config_spec.rb +6 -6
  55. data/spec/wavefront-cli/config_spec.rb +84 -44
  56. data/spec/wavefront-cli/controller_spec.rb +4 -2
  57. data/spec/wavefront-cli/dashboard_spec.rb +1 -1
  58. data/spec/wavefront-cli/derivedmetric_spec.rb +9 -7
  59. data/spec/wavefront-cli/display/base_spec.rb +1 -1
  60. data/spec/wavefront-cli/display/printer/long_spec.rb +6 -4
  61. data/spec/wavefront-cli/display/printer/terse_spec.rb +2 -2
  62. data/spec/wavefront-cli/event_spec.rb +14 -11
  63. data/spec/wavefront-cli/event_store_spec.rb +17 -13
  64. data/spec/wavefront-cli/externallink_spec.rb +5 -3
  65. data/spec/wavefront-cli/maintenancewindow_spec.rb +25 -19
  66. data/spec/wavefront-cli/message_spec.rb +3 -3
  67. data/spec/wavefront-cli/metricspolicy_spec.rb +30 -0
  68. data/spec/wavefront-cli/opt_handler_spec.rb +2 -2
  69. data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
  70. data/spec/wavefront-cli/output/csv_spec.rb +1 -1
  71. data/spec/wavefront-cli/output/hcl_spec.rb +1 -1
  72. data/spec/wavefront-cli/output/helpers.rb +1 -1
  73. data/spec/wavefront-cli/output/json_spec.rb +1 -1
  74. data/spec/wavefront-cli/output/ruby_spec.rb +1 -1
  75. data/spec/wavefront-cli/output/wavefront/query_spec.rb +1 -1
  76. data/spec/wavefront-cli/output/wavefront_spec.rb +1 -1
  77. data/spec/wavefront-cli/output/yaml_spec.rb +1 -1
  78. data/spec/wavefront-cli/proxy_spec.rb +1 -1
  79. data/spec/wavefront-cli/query_spec.rb +2 -2
  80. data/spec/wavefront-cli/role_spec.rb +4 -3
  81. data/spec/wavefront-cli/serviceaccount_spec.rb +7 -5
  82. data/spec/wavefront-cli/stdlib/array_spec.rb +1 -1
  83. data/spec/wavefront-cli/stdlib/string_spec.rb +4 -2
  84. data/spec/wavefront-cli/usage_spec.rb +2 -2
  85. data/spec/wavefront-cli/{write_spec.rb → write_class_spec.rb} +2 -15
  86. data/wavefront-cli.gemspec +4 -16
  87. metadata +17 -259
  88. data/spec/spec_helper.rb +0 -113
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f464387b5dfcc05cdec2af09eaf006ff9544d880185a21fc787ba25b2d1686c
4
- data.tar.gz: c90b1bd9e45e9aadcf4374dea2a3c8794c8560e371e5d597aad88f95ffcd813f
3
+ metadata.gz: '09fbd2dd451ea0b319a8d1a36ac1c0f3e95e186fc506363f47b5f8436e67d19d'
4
+ data.tar.gz: c2e562c485f9e520be34922d55f5b6e7dfca5c3f876cd20857ebc2030c2cfc17
5
5
  SHA512:
6
- metadata.gz: 24fb5ca35864e6624905e311430c73c16c5581d909f12af1e6183fac5e9717245c770a3bfcc552d60c78f63a43c077e38e43c7ce78317a71af9de535de5952b9
7
- data.tar.gz: 55ab4e7a41e3139141d018be4c71505e66d42a9ead87a006c5a39eb7c50a342257ef706cef24680523a08b7a8a865f59ef391958d5556bad2c7d9a18e186e053
6
+ metadata.gz: 103663abbe25ed7a75e2622e85ea1ce1e984da813b4a85b3128e8bf24aa6d2d95d63000e5efa87d5ad615211f7bdc6f3193bacc435de0c437b3134948b5078cd
7
+ data.tar.gz: c8bcfaafbe5da6fe7a5a3065cf51de47b67ed086a0e54f444d1e1b7260212ea22ad032325ce8c4135d5b0c36cdd62aed91e57c1e569ac63d541f2b3d9c6ca711
@@ -11,14 +11,14 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
 
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - name: Set env
16
16
  run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
17
17
 
18
- - name: Set up Ruby 2.7
18
+ - name: Set up Ruby 3.2
19
19
  uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: 2.7
21
+ ruby-version: 3.2
22
22
  - run: bundle install
23
23
 
24
24
  - name: Run tests
@@ -34,4 +34,4 @@ jobs:
34
34
  chmod 0600 ${HOME}/.gem/credentials
35
35
  gem push pkg/*.gem
36
36
  env:
37
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
37
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_PUSH_KEY}}"
@@ -9,9 +9,9 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
11
  matrix:
12
- ruby-version: [2.5.8, 2.6.6, 2.7.2]
12
+ ruby-version: [3.0, 3.1, 3.2, 3.3]
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
data/.rubocop.yml CHANGED
@@ -1,13 +1,12 @@
1
1
  ---
2
2
  AllCops:
3
- TargetRubyVersion: 2.5
3
+ TargetRubyVersion: 3.0
4
4
  NewCops: enable
5
5
 
6
6
  require:
7
7
  - rubocop-rake
8
8
  - rubocop-minitest
9
9
  - rubocop-performance
10
- - rubocop-performance
11
10
 
12
11
  Layout/LineLength:
13
12
  Max: 80 # Is nothing sacred?
@@ -17,7 +16,5 @@ Naming/VariableNumber:
17
16
  Enabled: false
18
17
  Style/IfUnlessModifier:
19
18
  Enabled: false # because it wants to make lines >80 chars
20
- Style/StringConcatenation:
21
- Enabled: false
22
19
  Style/OptionalBooleanParameter:
23
20
  Enabled: false
data/Gemfile CHANGED
@@ -2,3 +2,13 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
+
6
+ gem 'minitest', '~> 5.21', group: :development
7
+ gem 'rake', '~> 13.0', group: :development
8
+ gem 'rubocop', '~> 1.60', group: :development
9
+ gem 'rubocop-minitest', '~> 0.26', group: :development
10
+ gem 'rubocop-performance', '~> 1.15', group: :development
11
+ gem 'rubocop-rake', '~> 0.6', group: :development
12
+ gem 'spy', '~> 1.0', group: :development
13
+ gem 'webmock', '~> 3.18', group: :development
14
+ gem 'yard', '~> 0.9', group: :development
data/HISTORY.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 10.0.0 (2024-01-19)
4
+ * Remove support for Ruby < 3.0 (Breaking change.)
5
+ * Fix HTTP proxy write bug by bumping SDK dependency.
6
+ * Add `config cluster` command.
7
+ * Revamp `config` command internals and improve tests.
8
+
9
+ ## 9.0.0 (2023-01-20)
10
+ * Drop support for Ruby 2.5. (Breaking change.)
11
+ * Drop support for Ruby 2.6. (Breaking change.)
12
+ * Add `metricspolicy` command.
13
+ * `wf write` has changed. Tokens and API endpoints are now specified exactly
14
+ like other commands. This means certain options had to change. A proxy is
15
+ now specified with `-y` instead of `-E`; A timestamp is given with `-s`, not
16
+ `-t`. (Breaking change.)
17
+ * Unless told otherwise, `wf write` will write to a proxy over HTTP, rather
18
+ than over a socket. (Breaking change.)
19
+
3
20
  ## 8.5.1 (2021-01-28)
4
21
  * Fix stack trace when specifying an invalid time such as `Sunday`.
5
22
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Wavefront CLI
2
- [![Build Status](https://travis-ci.org/snltd/wavefront-cli.svg?branch=master)](https://travis-ci.org/snltd/wavefront-cli) [![Maintainability](https://api.codeclimate.com/v1/badges/9b712047af0b2dafc146/maintainability)](https://codeclimate.com/github/snltd/wavefront-cli/maintainability) [![Gem Version](https://badge.fury.io/rb/wavefront-cli.svg)](https://badge.fury.io/rb/wavefront-cli) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-cli?type=total)
2
+ [![Test](https://github.com/snltd/wavefront-cli/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/snltd/wavefront-cli/actions/workflows/test.yml) ![Release](https://github.com/snltd/wavefront-sdk/workflows/Release/badge.svg) [![Maintainability](https://api.codeclimate.com/v1/badges/9b712047af0b2dafc146/maintainability)](https://codeclimate.com/github/snltd/wavefront-cli/maintainability) [![Gem Version](https://badge.fury.io/rb/wavefront-cli.svg)](https://badge.fury.io/rb/wavefront-cli) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-cli?type=total)
3
3
 
4
4
  This is a complete command-line interface to
5
5
  [Wavefront](https://www.wavefront.com/)'s API. It also provides easy
@@ -15,7 +15,7 @@ $ gem install wavefront-cli
15
15
 
16
16
  It is built on [our Wavefront Ruby
17
17
  SDK](https://github.com/snltd/wavefront-sdk) and requires Ruby >=
18
- 2.5. It has no "native extension" dependencies.
18
+ 3.0. It has no "native extension" dependencies.
19
19
 
20
20
  For a far more comprehensive overview/tutorial, please read [this
21
21
  article](https://sysdef.xyz/article/wavefront-cli).
@@ -30,6 +30,7 @@ Usage:
30
30
  wf --help
31
31
 
32
32
  Commands:
33
+ account view and manage Wavefront accounts
33
34
  alert view and manage alerts
34
35
  apitoken view and your own API tokens
35
36
  cloudintegration view and manage cloud integrations
@@ -45,6 +46,7 @@ Commands:
45
46
  notificant view and manage Wavefront alert targets
46
47
  proxy view and manage proxies
47
48
  query run Wavefront queries
49
+ role view and manage roles
48
50
  savedsearch view and manage saved searches
49
51
  serviceaccount view and manage service accounts
50
52
  settings view and manage system preferences
@@ -49,7 +49,7 @@ module WavefrontCli
49
49
  # Overriding this method lets you map to something else.
50
50
  #
51
51
  def _sdk_class
52
- self.class.name.sub(/Cli/, '')
52
+ self.class.name.sub('Cli', '')
53
53
  end
54
54
 
55
55
  # Some subcommands don't make an API call, so they don't return
@@ -85,7 +85,7 @@ module WavefrontCli
85
85
  # that, override this method.
86
86
  #
87
87
  def validator_method
88
- "wf_#{klass_word}_id?".to_sym
88
+ :"wf_#{klass_word}_id?"
89
89
  end
90
90
 
91
91
  def validator_exception
@@ -206,7 +206,7 @@ module WavefrontCli
206
206
  #
207
207
  def method_word_list
208
208
  do_methods = methods.select { |m| m.to_s.start_with?('do_') }
209
- do_methods.map { |m| m.to_s.split('_')[1..-1] }.sort_by(&:length)
209
+ do_methods.map { |m| m.to_s.split('_')[1..] }.sort_by(&:length)
210
210
  end
211
211
 
212
212
  # Display a Ruby object as JSON, YAML, or human-readable. We
@@ -545,7 +545,7 @@ module WavefrontCli
545
545
  when Hash
546
546
  obj.each_pair do |k, v|
547
547
  if k == key && !v.to_s.empty?
548
- aggr.<< v
548
+ aggr << v
549
549
  else
550
550
  extract_values(v, key, aggr)
551
551
  end
@@ -29,7 +29,7 @@ class WavefrontCommandBase
29
29
  # @return [Array]
30
30
  #
31
31
  def common_options
32
- ['-E, --endpoint=URI cluster endpoint',
32
+ ['-E, --endpoint=URI Wavefront cluster endpoint',
33
33
  '-t, --token=TOKEN Wavefront authentication token']
34
34
  end
35
35
 
@@ -72,7 +72,7 @@ class WavefrontCommandBase
72
72
  # @return [String] the command keyword
73
73
  #
74
74
  def word
75
- self.class.name.sub(/WavefrontCommand/, '').downcase
75
+ self.class.name.sub('WavefrontCommand', '').downcase
76
76
  end
77
77
 
78
78
  def thing
@@ -80,7 +80,7 @@ class WavefrontCommandBase
80
80
  end
81
81
 
82
82
  def things
83
- thing + 's'
83
+ "#{thing}s"
84
84
  end
85
85
 
86
86
  # @return [String] the name of the SDK class which does the work
@@ -105,10 +105,11 @@ class WavefrontCommandBase
105
105
  text_arr = %w[Usage:]
106
106
 
107
107
  _commands.flatten.each do |cmd|
108
- text_arr.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width)
108
+ folded = "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width)
109
+ text_arr << " #{folded}"
109
110
  end
110
111
 
111
- text_arr.<< " #{CMD} #{word} --help"
112
+ text_arr << " #{CMD} #{word} --help"
112
113
  text_arr.join("\n")
113
114
  end
114
115
 
@@ -124,15 +125,15 @@ class WavefrontCommandBase
124
125
  global_option_text(width, term_width)
125
126
  end
126
127
 
127
- text_arr.<< 'Options:'
128
- _options.flatten.each { |o| text_arr.<< opt_row(o, width, term_width) }
128
+ text_arr << 'Options:'
129
+ _options.flatten.each { |o| text_arr << opt_row(o, width, term_width) }
129
130
  text_arr.join("\n")
130
131
  end
131
132
 
132
133
  def global_option_text(width, term_width)
133
134
  text_arr = ['Global options:']
134
- global_options.each { |o| text_arr.<< opt_row(o, width, term_width) }
135
- text_arr.<< ''
135
+ global_options.each { |o| text_arr << opt_row(o, width, term_width) }
136
+ text_arr << ''
136
137
  end
137
138
 
138
139
  # Formats an option string.
@@ -142,10 +143,12 @@ class WavefrontCommandBase
142
143
  # columns. This is used to indent following lines
143
144
  # @param term_width [Integer] the width of the user's terminal
144
145
  #
146
+ # rubocop:disable Lint/FormatParameterMismatch
145
147
  def opt_row(opt_str, width, term_width = TW)
146
148
  format(" %s %-#{width}s %s",
147
149
  *opt_str.split(/\s+/, 3)).opt_fold(term_width, width + 5)
148
150
  end
151
+ # rubocop:enable Lint/FormatParameterMismatch
149
152
 
150
153
  # @return [Integer] the width of the column containing short and
151
154
  # long options
@@ -165,6 +168,6 @@ class WavefrontCommandBase
165
168
  # @return [String] a full options string which docopt understands
166
169
  #
167
170
  def docopt
168
- commands + "\n\n" + options + "\n\n" + postscript
171
+ "#{commands}\n\n#{options}\n\n#{postscript}"
169
172
  end
170
173
  end
@@ -6,7 +6,7 @@ require_relative 'base'
6
6
  #
7
7
  class WavefrontCommandConfig < WavefrontCommandBase
8
8
  def description
9
- 'create and manage local configuration'
9
+ 'create and manage local configuration, and display debug info'
10
10
  end
11
11
 
12
12
  def _commands
@@ -16,15 +16,11 @@ class WavefrontCommandConfig < WavefrontCommandBase
16
16
  'setup [-D] [-c file] [<profile>]',
17
17
  'delete [-D] [-c file] <profile>',
18
18
  'envvars',
19
+ "cluster #{CMN}",
19
20
  'about']
20
21
  end
21
22
 
22
23
  def _options
23
- ['-c, --config=FILE path to configuration file',
24
- '-D, --debug enable debug mode']
25
- end
26
-
27
- def global_options
28
- []
24
+ [common_options]
29
25
  end
30
26
  end
@@ -45,7 +45,7 @@ class WavefrontCommandDerivedmetric < WavefrontCommandBase
45
45
  '-d, --desc=STRING additional information about query',
46
46
  '-i, --interval=INTEGER execute query every n minutes [default: 1]',
47
47
  '-r, --range=INTEGER include results in the last n minutes ' \
48
- '[default: 5]',
48
+ '[default: 5]',
49
49
  "-u, --update update an existing #{thing}",
50
50
  "-U, --upsert import new or update existing #{thing}"]
51
51
  end
@@ -23,8 +23,8 @@ class WavefrontCommandMetric < WavefrontCommandBase
23
23
 
24
24
  def postscript
25
25
  "\nNOTE: the 'list under' and 'list all' sub-commands use the unoffical " \
26
- "'chart' endpoint, which is not guaranteed to remain stable.\n\n" \
27
- 'Both commands have to make a lot of API calls, and may take a ' \
28
- 'very long time to run.'.cmd_fold(TW, 0)
26
+ "'chart' endpoint, which is not guaranteed to remain stable.\n\n" \
27
+ 'Both commands have to make a lot of API calls, and may take a ' \
28
+ 'very long time to run.'.cmd_fold(TW, 0)
29
29
  end
30
30
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ # Define the metricspolicy command.
6
+ #
7
+ class WavefrontCommandMetricspolicy < WavefrontCommandBase
8
+ def thing
9
+ 'metrics policy'
10
+ end
11
+
12
+ def things
13
+ 'metrics policies'
14
+ end
15
+
16
+ def sdk_class
17
+ 'MetricsPolicy'
18
+ end
19
+
20
+ def _commands
21
+ ["describe #{CMN} [-v version]",
22
+ "history #{CMN} [-o offset] [-L limit]",
23
+ "revert #{CMN} <version>",
24
+ "update #{CMN} <file>"]
25
+ end
26
+
27
+ def _options
28
+ [common_options,
29
+ "-o, --offset=n start from nth #{thing}",
30
+ "-L, --limit=COUNT number of #{things} or revisions to list",
31
+ "-v, --version=INTEGER version of #{thing}"]
32
+ end
33
+ end
@@ -12,11 +12,11 @@ class WavefrontCommandQuery < WavefrontCommandBase
12
12
  def _commands
13
13
  ['aliases [-DV] [-c file] [-P profile]',
14
14
  "#{CMN} [-g granularity] [-s time] [-e time] " \
15
- '[-ikvCGKOW] [-S mode] [-N name] [-p points] [-F options] <query>',
15
+ '[-ikvCGKOW] [-S mode] [-N name] [-p points] [-F options] <query>',
16
16
  "raw #{CMN} [-H host] [-s time] [-e time] " \
17
- '[-F options] <metric>',
17
+ '[-F options] <metric>',
18
18
  "run #{CMN} [-g granularity] [-s time] [-e time] " \
19
- '[-F options] [-WkivO] [-S mode] [-N name] [-p points] <alias>']
19
+ '[-F options] [-WkivO] [-S mode] [-N name] [-p points] <alias>']
20
20
  end
21
21
 
22
22
  def _options
@@ -34,7 +34,7 @@ class WavefrontCommandQuery < WavefrontCommandBase
34
34
  '-O, --obsolete include metrics unreported for > 4 weeks',
35
35
  '-H, --host=STRING host or source to query on',
36
36
  '-F, --format-opts=STRING comma-separated options to pass to ' \
37
- 'output formatter',
37
+ 'output formatter',
38
38
  '-k, --nospark do not show sparkline',
39
39
  '-C, --nocache do not use the query cache',
40
40
  '-K, --nostrict allow points outside the query window',
@@ -45,7 +45,7 @@ class WavefrontCommandQuery < WavefrontCommandBase
45
45
  def postscript
46
46
  'The query command has an additional output format. Using ' \
47
47
  "'-f wavefront' produces output suitable for feeding back into a " \
48
- "proxy. Other output formats are 'yaml', 'json', 'ruby', "\
48
+ "proxy. Other output formats are 'yaml', 'json', 'ruby', " \
49
49
  "and 'csv'. CSV format options are 'headers' (print column headers); " \
50
50
  "'tagkeys' (print tags as key=value rather than value); and 'quote' " \
51
51
  '(force quoting of every CSV element).'.cmd_fold(TW, 0)
@@ -10,24 +10,24 @@ class WavefrontCommandWrite < WavefrontCommandBase
10
10
  end
11
11
 
12
12
  def _commands
13
- ['point [-DnViq] [-c file] [-P profile] [-E proxy] [-t time] ' \
13
+ ["point #{CMN} [-iq] [-y proxy] [-s time] " \
14
14
  '[-p port] [-H host] [-T tag...] [-u method] [-S socket] <metric> ' \
15
15
  '[--] <value>',
16
- 'distribution [-DnViq] [-c file] [-P profile] [-E proxy] [-H host] ' \
17
- '[-p port] [-T tag...] [-u method] [-S socket] [-I interval] ' \
16
+ "distribution #{CMN} [-iq] [-y proxy] " \
17
+ '[-H host] [-p port] [-T tag...] [-u method] [-S socket] [-I interval] ' \
18
18
  '<metric> [--] <val>...',
19
- 'file [-DnViq] [-c file] [-P profile] [-E proxy] [-H host] ' \
19
+ "file #{CMN} [-iq] [-y proxy] [-H host] " \
20
20
  '[-p port] [-F infileformat] [-m metric] [-T tag...] [-I interval] ' \
21
21
  '[-u method] [-S socket] <file>',
22
- 'noise [-DnViq] [-P profile] [-E proxy] [-H host] [-p port] ' \
22
+ "noise #{CMN} [-iq] [-y proxy] [-H host] [-p port] " \
23
23
  '[-T tag...] [-I interval] [-x value] [-X value] <metric>']
24
24
  end
25
25
 
26
26
  def _options
27
- ['-E, --proxy=URI proxy endpoint',
28
- '-t, --time=TIME time of data point (omit to use ' \
29
- 'current time)',
30
- '-H, --host=STRING source host', \
27
+ [common_options,
28
+ '-y, --proxy=URI proxy endpoint',
29
+ '-s, --ts=TIME timestamp of data point (omit for "now")',
30
+ '-H, --host=STRING source host',
31
31
  '-p, --port=INT Wavefront proxy port',
32
32
  '-T, --tag=TAG point tag in key=value form',
33
33
  '-F, --infileformat=STRING format of input file or stdin',
@@ -50,9 +50,9 @@ class WavefrontCommandWrite < WavefrontCommandBase
50
50
  "with the '-F' option. Use 't' for timestamp, 'm' for metric " \
51
51
  "name, 'v' for value, 's' for source, 'd' for a comma-separated " \
52
52
  "distribution, and 'T' for tags. Put 'T' last. Currently " \
53
- "supported transport methods are 'socket' (write to a proxy: the " \
54
- "default); 'api' (write directly to Wavefront); 'http' (write to " \
55
- "a proxy over HTTP); and 'unix' (write to a local Unix socket)."
53
+ "supported transport methods are 'http' (write to a proxy over HTTP: " \
54
+ "the default); 'api' (write directly to Wavefront); 'proxy' (send raw " \
55
+ "data to a proxy); and 'socket' (write to a local Unix socket)."
56
56
  .cmd_fold(TW, 0)
57
57
  end
58
58
  end
@@ -6,11 +6,7 @@ require_relative 'base'
6
6
 
7
7
  module WavefrontCli
8
8
  #
9
- # Create and manage a local configuration file. This class doesn't
10
- # fit many of the assumptions made by the Base class. (Primarily,
11
- # that it will consume the SDK.) Rather than split everything up,
12
- # we're going to do some bad programming and override a couple of
13
- # methods in the parent class to force different behaviour.
9
+ # Create and manage a local configuration file.
14
10
  #
15
11
  class Config < WavefrontCli::Base
16
12
  attr_reader :config_file, :profile
@@ -34,41 +30,39 @@ module WavefrontCli
34
30
  test: proc { |v| %w[human json yaml].include?(v) } }
35
31
  ].freeze
36
32
 
37
- RX = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/.freeze
33
+ RX = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/
38
34
 
39
- # rubocop:disable Lint/MissingSuper
40
- def initialize(options)
41
- @options = options
35
+ def post_initialize(options)
42
36
  @config_file = _config_file
43
37
  @profile = options[:'<profile>'] || 'default'
44
38
  end
45
- # rubocop:enable Lint/MissingSuper
39
+
40
+ def _sdk_class
41
+ 'Wavefront::Cluster'
42
+ end
46
43
 
47
44
  def do_location
48
- puts config_file
45
+ config_file
49
46
  end
50
47
 
51
48
  def do_profiles
52
- read_config.sections.each { |s| puts s }
49
+ read_config.sections.sort
53
50
  end
54
51
 
55
52
  def do_show
56
53
  present?
57
- puts IO.read(config_file)
54
+ File.read(config_file)
58
55
  end
59
56
 
60
57
  def do_about
61
58
  require 'wavefront-sdk/defs/version'
62
- require_relative 'display/base'
63
59
 
64
- info = { 'wf version': WF_CLI_VERSION,
65
- 'wf path': CMD_PATH.realpath.to_s,
66
- 'SDK version': WF_SDK_VERSION,
67
- 'SDK location': WF_SDK_LOCATION.to_s,
68
- 'Ruby version': RUBY_VERSION,
69
- 'Ruby platform': Gem::Platform.local.os.capitalize }
70
-
71
- WavefrontDisplay::Base.new(info).long_output
60
+ { '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,
65
+ 'Ruby platform': Gem::Platform.local.os.capitalize }
72
66
  end
73
67
 
74
68
  def base_config
@@ -97,7 +91,7 @@ module WavefrontCli
97
91
  prof_arr = ["[#{profile}]"]
98
92
 
99
93
  CONFIGURABLES.each do |c|
100
- prof_arr.<< format('%<key>s=%<value>s',
94
+ prof_arr << format('%<key>s=%<value>s',
101
95
  key: c[:key],
102
96
  value: read_thing(c))
103
97
  end
@@ -121,25 +115,27 @@ module WavefrontCli
121
115
  end
122
116
 
123
117
  def do_envvars
124
- %w[WAVEFRONT_ENDPOINT WAVEFRONT_TOKEN WAVEFRONT_PROXY].each do |v|
125
- puts format('%-20<var>s %<value>s',
126
- var: v,
127
- value: ENV[v] || 'unset')
118
+ %w[WAVEFRONT_ENDPOINT WAVEFRONT_TOKEN WAVEFRONT_PROXY].map do |v|
119
+ format('%-20<var>s %<value>s', var: v, value: ENV[v] || 'unset')
128
120
  end
129
121
  end
130
122
 
131
- def validate_opts; end
123
+ def do_cluster
124
+ wf.describe
125
+ end
132
126
 
133
- def display(_data, _method); end
127
+ def validate_opts; end
134
128
 
135
- def run
136
- dispatch
129
+ def no_api_response
130
+ %w[do_location do_profiles do_show do_envvars do_about]
137
131
  end
138
132
 
133
+ # def display(_data, _method); end
134
+
139
135
  def input_prompt(label, default)
140
136
  ret = format(' %<label>s', label: label)
141
- ret.<< format(' [%<value>s]', value: default) unless default.nil?
142
- ret + ':> '
137
+ ret << format(' [%<value>s]', value: default) unless default.nil?
138
+ "#{ret}:> "
143
139
  end
144
140
 
145
141
  # Read STDIN and strip the whitespace. The rescue is there to
@@ -156,10 +152,10 @@ module WavefrontCli
156
152
  #
157
153
  def read_thing(thing)
158
154
  print input_prompt(thing[:text], thing[:default])
159
- validate_input(read_input, thing[:default], thing[:test])
155
+ validate_thing_input(read_input, thing[:default], thing[:test])
160
156
  end
161
157
 
162
- def validate_input(input, default, test)
158
+ def validate_thing_input(input, default, test)
163
159
  if input.empty?
164
160
  raise WavefrontCli::Exception::MandatoryValue if default.nil?
165
161
 
@@ -3,6 +3,7 @@
3
3
  require 'pathname'
4
4
 
5
5
  module WavefrontCli
6
+ #
6
7
  # Universal truths
7
8
  #
8
9
  module Constants
@@ -24,11 +25,11 @@ module WavefrontCli
24
25
 
25
26
  # Default configuration file
26
27
  #
27
- DEFAULT_CONFIG = (Pathname.new(ENV['HOME']) + '.wavefront').freeze
28
+ DEFAULT_CONFIG = Pathname.new(Dir.home).join('.wavefront').freeze
28
29
 
29
30
  # Split regex for searches
30
31
  #
31
- SEARCH_SPLIT = /\^|!\^|=|!=|~|!~/.freeze
32
+ SEARCH_SPLIT = /\^|!\^|=|!=|~|!~/
32
33
 
33
34
  # Where we store local event information
34
35
  #
@@ -7,8 +7,8 @@
7
7
 
8
8
  if defined?(DEVELOPMENT)
9
9
  dir = Pathname.new(__dir__).realpath.parent.parent.parent
10
- $LOAD_PATH.<< dir + 'lib'
11
- $LOAD_PATH.<< dir + 'wavefront-sdk' + 'lib'
10
+ $LOAD_PATH << dir.join('lib')
11
+ $LOAD_PATH << dir.join('wavefront-sdk', 'lib')
12
12
  end
13
13
 
14
14
  require 'pathname'
@@ -20,7 +20,7 @@ require_relative 'opt_handler'
20
20
  require_relative 'exception_handler'
21
21
  require_relative 'stdlib/string'
22
22
 
23
- CMD_DIR = Pathname.new(__dir__) + 'commands'
23
+ CMD_DIR = Pathname.new(__dir__).join('commands')
24
24
 
25
25
  # Dynamically generate a CLI interface from files which describe
26
26
  # each subcomand.
@@ -65,13 +65,13 @@ class WavefrontCliController
65
65
  'Commands:']
66
66
 
67
67
  cmds.sort.each do |k, v|
68
- s.<< format(' %-18<command>s %<desc>s',
68
+ s << format(' %-18<command>s %<desc>s',
69
69
  command: k,
70
70
  desc: v.description)
71
71
  end
72
72
 
73
- s.<< ''
74
- s.<< "Use '#{CMD} <command> --help' for further information."
73
+ s << ''
74
+ s << "Use '#{CMD} <command> --help' for further information."
75
75
  s.join("\n")
76
76
  end
77
77
  # rubocop:enable Metrics/MethodLength
@@ -124,7 +124,7 @@ class WavefrontCliController
124
124
 
125
125
  def load_cli_class(cmd, opts)
126
126
  require_relative File.join('.', cmds[cmd].sdk_file)
127
- Object.const_get('WavefrontCli').const_get(cmds[cmd].sdk_class).new(opts)
127
+ Object.const_get(:WavefrontCli).const_get(cmds[cmd].sdk_class).new(opts)
128
128
  end
129
129
 
130
130
  def run_command(cli_class_obj)
@@ -145,15 +145,19 @@ class WavefrontCliController
145
145
  # @param error [WavefrontCli::Exception::CredentialError]
146
146
  #
147
147
  def handle_missing_credentials(error)
148
- if DEFAULT_CONFIG.exist? && DEFAULT_CONFIG.file?
149
- abort "Credential error. #{error.message}"
150
- else
151
- puts 'No credentials supplied on the command line or via ' \
152
- 'environment variables, and no configuration file found. ' \
153
- "Please run 'wf config setup' to create configuration."
154
- .fold(TW, 0)
155
- exit 1
148
+ message = error.message.capitalize
149
+ message << ('.') unless message.end_with?('.')
150
+
151
+ puts "Credential error. #{message}"
152
+
153
+ unless DEFAULT_CONFIG.exist? && DEFAULT_CONFIG.file?
154
+ puts
155
+ puts 'You can pass credentials on the command line or via ' \
156
+ "environment variables. You may also run 'wf config setup' to " \
157
+ 'create a config file.'.fold(TW, 0)
156
158
  end
159
+
160
+ exit 1
157
161
  end
158
162
 
159
163
  # Each command is defined in its own file. Dynamically load all