wavefront-cli 8.5.0 → 9.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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +37 -0
  3. data/.github/workflows/test.yml +23 -0
  4. data/.rubocop.yml +10 -9
  5. data/HISTORY.md +15 -0
  6. data/README.md +4 -2
  7. data/lib/wavefront-cli/base.rb +2 -2
  8. data/lib/wavefront-cli/commands/.rubocop.yml +2 -13
  9. data/lib/wavefront-cli/commands/base.rb +10 -9
  10. data/lib/wavefront-cli/commands/derivedmetric.rb +1 -1
  11. data/lib/wavefront-cli/commands/metric.rb +3 -3
  12. data/lib/wavefront-cli/commands/metricspolicy.rb +33 -0
  13. data/lib/wavefront-cli/commands/query.rb +5 -5
  14. data/lib/wavefront-cli/commands/write.rb +12 -12
  15. data/lib/wavefront-cli/config.rb +4 -4
  16. data/lib/wavefront-cli/constants.rb +2 -1
  17. data/lib/wavefront-cli/controller.rb +19 -15
  18. data/lib/wavefront-cli/display/base.rb +3 -2
  19. data/lib/wavefront-cli/display/metricspolicy.rb +15 -0
  20. data/lib/wavefront-cli/display/printer/long.rb +11 -13
  21. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -3
  22. data/lib/wavefront-cli/display/query.rb +1 -1
  23. data/lib/wavefront-cli/display/write.rb +2 -1
  24. data/lib/wavefront-cli/event.rb +2 -2
  25. data/lib/wavefront-cli/event_store.rb +2 -2
  26. data/lib/wavefront-cli/exception.rb +21 -0
  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 +3 -4
  32. data/lib/wavefront-cli/output/csv/query.rb +2 -2
  33. data/lib/wavefront-cli/output/hcl/dashboard.rb +6 -6
  34. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +1 -1
  35. data/lib/wavefront-cli/output/wavefront/query.rb +7 -7
  36. data/lib/wavefront-cli/query.rb +1 -1
  37. data/lib/wavefront-cli/settings.rb +3 -4
  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 +14 -18
  42. data/spec/.rubocop.yml +2 -17
  43. data/spec/constants.rb +4 -5
  44. data/spec/support/command_base.rb +12 -0
  45. data/spec/support/minitest_assertions.rb +15 -11
  46. data/spec/support/output_tester.rb +2 -2
  47. data/spec/support/supported_commands.rb +3 -1
  48. data/spec/test_mixins/import.rb +2 -2
  49. data/spec/test_mixins/search.rb +9 -7
  50. data/spec/test_mixins/set.rb +1 -1
  51. data/spec/wavefront-cli/account_spec.rb +6 -4
  52. data/spec/wavefront-cli/alert_spec.rb +29 -6
  53. data/spec/wavefront-cli/commands/base_spec.rb +4 -4
  54. data/spec/wavefront-cli/commands/config_spec.rb +3 -3
  55. data/spec/wavefront-cli/config_spec.rb +3 -3
  56. data/spec/wavefront-cli/controller_spec.rb +4 -0
  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/printer/long_spec.rb +5 -3
  60. data/spec/wavefront-cli/display/printer/terse_spec.rb +1 -1
  61. data/spec/wavefront-cli/event_spec.rb +14 -11
  62. data/spec/wavefront-cli/event_store_spec.rb +16 -12
  63. data/spec/wavefront-cli/externallink_spec.rb +5 -3
  64. data/spec/wavefront-cli/maintenancewindow_spec.rb +25 -19
  65. data/spec/wavefront-cli/message_spec.rb +3 -3
  66. data/spec/wavefront-cli/metricspolicy_spec.rb +30 -0
  67. data/spec/wavefront-cli/opt_handler_spec.rb +4 -4
  68. data/spec/wavefront-cli/output/helpers.rb +1 -1
  69. data/spec/wavefront-cli/proxy_spec.rb +1 -1
  70. data/spec/wavefront-cli/query_spec.rb +1 -1
  71. data/spec/wavefront-cli/role_spec.rb +4 -3
  72. data/spec/wavefront-cli/serviceaccount_spec.rb +7 -7
  73. data/spec/wavefront-cli/stdlib/string_spec.rb +3 -1
  74. data/spec/wavefront-cli/usage_spec.rb +1 -1
  75. data/spec/wavefront-cli/{write_spec.rb → write_class_spec.rb} +1 -14
  76. data/wavefront-cli.gemspec +13 -12
  77. metadata +72 -146
  78. data/.travis.yml +0 -20
  79. data/spec/spec_helper.rb +0 -113
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 363b1be94331165aacf1538c797d07bdbefda71e801335bb4e35df97cb0bd950
4
- data.tar.gz: 5563b27f93c679dde5947c220d80c37816ba6faf8844d08111cbf7dcc65a76c1
3
+ metadata.gz: 1040d65b6cf4352d960ff941f05f3bd5e924a4ebc13d1a0cff48c8920f1b426a
4
+ data.tar.gz: 841d25680790e0c8cf8623d09fc6bc6720c725f7b415f7342263d9e66501eb02
5
5
  SHA512:
6
- metadata.gz: ce61f68ba09a6ba395143fa92abeadcdb0de127f8991fe61b979ae49379d026973c5d47a09d6d4f0b306006a15f95a717cac02160af0b727f2858ba66a9fddae
7
- data.tar.gz: 111d9d52a0e0c3955164e1872198531b9e2bd61184dc430050029efdf8d19f9cd845885a7f1d5d5685d03dbf7de0845453d95f888e13eb0195b83fd25437116d
6
+ metadata.gz: 120360b39776bd3711df4bd455cc4785d880447fc33c625ce5b30d9a69f29f51717f5133be78af65657f424d31188fc69afe8183d72cf8d88717cd20825922aa
7
+ data.tar.gz: 452d2d4e951dfeb02ca1a104fab5401feaaf8a9f3c7b1e649afb3eaebe3e5307f47fb0273cefc947de0e0fd655c761eee0e25bea5289279b7132458f071f6cf6
@@ -0,0 +1,37 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '[0-9]+.[0-9]+.[0-9]+'
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Set env
16
+ run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
17
+
18
+ - name: Set up Ruby 3.0
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: 3.0
22
+ - run: bundle install
23
+
24
+ - name: Run tests
25
+ run: bundle exec rake
26
+
27
+ - name: Build Gem
28
+ run: bundle exec rake build
29
+
30
+ - name: Publish to RubyGems
31
+ run: |
32
+ mkdir -p ${HOME}/.gem
33
+ echo -e "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}" >${HOME}/.gem/credentials
34
+ chmod 0600 ${HOME}/.gem/credentials
35
+ gem push pkg/*.gem
36
+ env:
37
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_PUSH_KEY}}"
@@ -0,0 +1,23 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches-ignore: release
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ ruby-version: [2.7.7, 3.1.3, 3.2.0]
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby-version }}
19
+ bundler-cache: true
20
+ - name: Install dependencies
21
+ run: bundle install
22
+ - name: Run tests
23
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,19 +1,20 @@
1
1
  ---
2
-
3
2
  AllCops:
4
- TargetRubyVersion: 2.5
3
+ TargetRubyVersion: 2.7
5
4
  NewCops: enable
6
5
 
6
+ require:
7
+ - rubocop-rake
8
+ - rubocop-minitest
9
+ - rubocop-performance
10
+
11
+ Layout/LineLength:
12
+ Max: 80 # Is nothing sacred?
7
13
  Metrics/ClassLength:
8
14
  Max: 400
9
-
15
+ Naming/VariableNumber:
16
+ Enabled: false
10
17
  Style/IfUnlessModifier:
11
18
  Enabled: false # because it wants to make lines >80 chars
12
- Style/StringConcatenation:
13
- Enabled: false
14
19
  Style/OptionalBooleanParameter:
15
20
  Enabled: false
16
-
17
- # Is nothing sacred?
18
- Layout/LineLength:
19
- Max: 80
data/HISTORY.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.0.0 (2023-01-20)
4
+
5
+ * Drop support for Ruby 2.5. (Breaking change.)
6
+ * Drop support for Ruby 2.6. (Breaking change.)
7
+ * Add `metricspolicy` command.
8
+ * `wf write` has changed. Tokens and API endpoints are now specified exactly
9
+ like other commands. This means certain options had to change. A proxy is
10
+ now specified with `-y` instead of `-E`; A timestamp is given with `-s`, not
11
+ `-t`. (Breaking change.)
12
+ * Unless told otherwise, `wf write` will write to a proxy over HTTP, rather
13
+ than over a socket. (Breaking change.)
14
+
15
+ ## 8.5.1 (2021-01-28)
16
+ * Fix stack trace when specifying an invalid time such as `Sunday`.
17
+
3
18
  ## 8.5.0 (2021-01-12)
4
19
  * Allow attachment of roles and ingestion policies when creating service
5
20
  accounts.
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
+ 2.7. 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
@@ -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
@@ -1,19 +1,8 @@
1
1
  ---
2
- AllCops:
3
- NewCops: enable
2
+ inherit_from:
3
+ - ../../../.rubocop.yml
4
4
 
5
5
  # There are long things in here, but they're fine
6
6
  #
7
7
  Metrics/MethodLength:
8
8
  Max: 25
9
-
10
- # Is nothing sacred?
11
- Layout/LineLength:
12
- Max: 80
13
-
14
- Style/IfUnlessModifier:
15
- Enabled: false # because it wants to make lines >80 chars
16
- Style/StringConcatenation:
17
- Enabled: false
18
- Style/OptionalBooleanParameter:
19
- Enabled: false
@@ -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
 
@@ -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.
@@ -165,6 +166,6 @@ class WavefrontCommandBase
165
166
  # @return [String] a full options string which docopt understands
166
167
  #
167
168
  def docopt
168
- commands + "\n\n" + options + "\n\n" + postscript
169
+ "#{commands}\n\n#{options}\n\n#{postscript}"
169
170
  end
170
171
  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
@@ -54,7 +54,7 @@ module WavefrontCli
54
54
 
55
55
  def do_show
56
56
  present?
57
- puts IO.read(config_file)
57
+ puts File.read(config_file)
58
58
  end
59
59
 
60
60
  def do_about
@@ -97,7 +97,7 @@ module WavefrontCli
97
97
  prof_arr = ["[#{profile}]"]
98
98
 
99
99
  CONFIGURABLES.each do |c|
100
- prof_arr.<< format('%<key>s=%<value>s',
100
+ prof_arr << format('%<key>s=%<value>s',
101
101
  key: c[:key],
102
102
  value: read_thing(c))
103
103
  end
@@ -138,8 +138,8 @@ module WavefrontCli
138
138
 
139
139
  def input_prompt(label, default)
140
140
  ret = format(' %<label>s', label: label)
141
- ret.<< format(' [%<value>s]', value: default) unless default.nil?
142
- ret + ':> '
141
+ ret << format(' [%<value>s]', value: default) unless default.nil?
142
+ "#{ret}:> "
143
143
  end
144
144
 
145
145
  # Read STDIN and strip the whitespace. The rescue is there to
@@ -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,7 +25,7 @@ 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
  #
@@ -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
@@ -399,9 +399,10 @@ module WavefrontDisplay
399
399
  # @return [String, String] DateTime formatter, strptime formatter
400
400
  #
401
401
  def time_formats(str)
402
- if str =~ /^\d{13}$/
402
+ case str
403
+ when /^\d{13}$/
403
404
  ['%Q', HUMAN_TIME_FORMAT_MS]
404
- elsif str =~ /^\d{10}$/
405
+ when /^\d{10}$/
405
406
  ['%s', HUMAN_TIME_FORMAT]
406
407
  else
407
408
  raise ArgumentError
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module WavefrontDisplay
6
+ #
7
+ # Format human-readable output of the metrics policy.
8
+ #
9
+ class MetricsPolicy < Base
10
+ def do_history
11
+ readable_time_arr(:updateTime)
12
+ long_output
13
+ end
14
+ end
15
+ end
@@ -84,7 +84,7 @@ module WavefrontDisplayPrinter
84
84
  elsif data.is_a?(Array)
85
85
  append_array(data, aggr, depth, last_key)
86
86
  else
87
- aggr.<< ['', preened_value(data), depth]
87
+ aggr << ['', preened_value(data), depth]
88
88
  end
89
89
  end
90
90
  # rubocop:enable Style/CaseLikeIf
@@ -99,16 +99,14 @@ module WavefrontDisplayPrinter
99
99
  # @return [Integer]
100
100
  #
101
101
  def longest_key_col(data)
102
- data.map { |d| d[0].size + opts[:padding] + opts[:indent] * d[2] }.max
102
+ data.map { |d| d[0].size + opts[:padding] + (opts[:indent] * d[2]) }.max
103
103
  end
104
104
 
105
105
  # Turn the list made by #make_list into user output
106
106
  # @return [String]
107
107
  #
108
108
  def to_s
109
- list.map do |item|
110
- stringify_line(item)
111
- end.join("\n")
109
+ list.map { |item| stringify_line(item) }.join("\n")
112
110
  end
113
111
 
114
112
  # @param item [Array] of the form [key, value, indent_level]
@@ -162,7 +160,7 @@ module WavefrontDisplayPrinter
162
160
  elsif v.is_a?(Array)
163
161
  aggr = append_array_values(k, v, aggr, depth)
164
162
  else
165
- aggr.<< [k, smart_value(v), depth]
163
+ aggr << [k, smart_value(v), depth]
166
164
  end
167
165
  end
168
166
 
@@ -183,7 +181,7 @@ module WavefrontDisplayPrinter
183
181
 
184
182
  if opts[:separator] && element.is_a?(Hash) && i < data.size &&
185
183
  depth < opts[:sep_depth]
186
- aggr.<< ['', :separator, depth]
184
+ aggr << ['', :separator, depth]
187
185
  end
188
186
  end
189
187
 
@@ -202,9 +200,9 @@ module WavefrontDisplayPrinter
202
200
  #
203
201
  def append_hash_values(key, values, aggr, depth)
204
202
  if values.empty? && opts[:none]
205
- aggr.<< [key, '<none>', depth]
203
+ aggr << [key, '<none>', depth]
206
204
  else
207
- aggr.<< [key, nil, depth]
205
+ aggr << [key, nil, depth]
208
206
  make_list(values, aggr, depth + 1)
209
207
  end
210
208
  end
@@ -218,13 +216,13 @@ module WavefrontDisplayPrinter
218
216
  #
219
217
  def append_array_values(key, values, aggr, depth)
220
218
  if values.empty? && opts[:none]
221
- aggr.<< [key, '<none>', depth]
222
- elsif values.all? { |w| w.is_a?(String) }
219
+ aggr << [key, '<none>', depth]
220
+ elsif values.all?(String)
223
221
  values.sort!
224
- aggr.<< [key, preened_value(values.shift), depth]
222
+ aggr << [key, preened_value(values.shift), depth]
225
223
  make_list(values, aggr, depth, key)
226
224
  else
227
- aggr.<< [key, nil, depth]
225
+ aggr << [key, nil, depth]
228
226
  make_list(values, aggr, depth + 1, key)
229
227
  end
230
228
  end
@@ -16,7 +16,7 @@ class WavefrontSparkline
16
16
  attr_reader :sparkline
17
17
 
18
18
  def initialize(series)
19
- @sparkline = '>' + generate_sparkline(series) + '<'
19
+ @sparkline = ">#{generate_sparkline(series)}<"
20
20
  end
21
21
 
22
22
  # @return [String] the block corresponding to the given value in
@@ -38,8 +38,8 @@ class WavefrontSparkline
38
38
  def make_fit(vals)
39
39
  return vals if vals.size < SPARK_WIDTH
40
40
 
41
- vals.<< vals.last if vals.size.odd?
42
- ret = vals.each_slice(2).with_object([]) { |s, a| a.<< s.inject(:+) / 2 }
41
+ vals << vals.last if vals.size.odd?
42
+ ret = vals.each_slice(2).with_object([]) { |s, a| a << (s.sum / 2) }
43
43
  make_fit(ret)
44
44
  end
45
45
 
@@ -86,7 +86,7 @@ module WavefrontDisplay
86
86
  if data.empty?
87
87
  puts 'No aliases defined.'
88
88
  else
89
- data.each_key { |k| puts k.to_s[2..-1] }
89
+ data.each_key { |k| puts k.to_s[2..] }
90
90
  end
91
91
  end
92
92