wavefront-cli 4.4.1 → 4.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2433758d7cf885eb814ce50935fca5325d6a5ae01060eb407cb17e74e36da6c7
4
- data.tar.gz: 6fd760d2439cd0c81f125f8d6df72e5eff5702f1d574d73b899eef6b4f646952
3
+ metadata.gz: 873187a820bc7cb2248cc10eb22ce76c12d95925651baa3c53972d5f7440a892
4
+ data.tar.gz: e0ab5dd4af22d88eb3f5d412dcaa08fb2e58906bf4044178c074dacde734159e
5
5
  SHA512:
6
- metadata.gz: 96c2a9221dbb07add7e115bdfd5e3499739022055875d9fdde0381965f87a49e7deb7806c98f1dd0e30b983d58ec29c8457b850841a998d20c9253f821368e38
7
- data.tar.gz: aa66e5930f5319c9b8597510457e4037ecfe936118392c2a388ca566b9d4d2c9b83eab70bfda862b810decd34680cb1ec4d4697415d9675d40cff640e3563d09
6
+ metadata.gz: 4432d6d046bc4c55530f10d8e765e5528f04432a9cfbdc4ab4e9a0899beae778885b70035c4cc570c669c3865ce0aa91c537320c6e2d62e0167e0b0123ea44e7
7
+ data.tar.gz: 2e9bb61ac0e004f412e3e00420f3e93d4795961ec3f63dc58ff6077efd1d502da4de880126ae562e5f992bc78196ee4ba61b151f14db43e62917bfbbe743be92
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.2 (2019-10-31)
4
+ * Bugfix: `dashboard import --update` didn't work when reading from stdin.
5
+ * Better handling of tag values in brief listings.
6
+
3
7
  ## 4.4.1 (2019-10-31)
4
8
  * Elegantly handle requests to print non-existent fields.
5
9
 
@@ -363,11 +363,11 @@ module WavefrontCli
363
363
  end
364
364
 
365
365
  def load_json(file)
366
- JSON.parse(IO.read(file), symbolize_names: true)
366
+ read_json(IO.read(file))
367
367
  end
368
368
 
369
369
  def load_yaml(file)
370
- YAML.safe_load(IO.read(file), symbolize_names: true)
370
+ read_yaml(IO.read(file))
371
371
  end
372
372
 
373
373
  # Read STDIN and return a Ruby object, assuming that STDIN is
@@ -383,9 +383,9 @@ module WavefrontCli
383
383
  raw = STDIN.read
384
384
 
385
385
  if raw.start_with?('---')
386
- YAML.safe_load(raw)
386
+ read_yaml(raw)
387
387
  else
388
- JSON.parse(raw)
388
+ read_json(raw)
389
389
  end
390
390
  rescue RuntimeError
391
391
  raise Wavefront::Exception::UnparseableInput
@@ -642,5 +642,15 @@ module WavefrontCli
642
642
  aggr
643
643
  end
644
644
  # rubocop:enable Metrics/MethodLength
645
+
646
+ private
647
+
648
+ def read_json(io)
649
+ JSON.parse(io, symbolize_names: true)
650
+ end
651
+
652
+ def read_yaml(io)
653
+ YAML.safe_load(io, symbolize_names: true)
654
+ end
645
655
  end
646
656
  end
@@ -8,7 +8,7 @@ module WavefrontDisplayPrinter
8
8
  # Print values which are per-row. The terse listings, primarily
9
9
  #
10
10
  class Terse
11
- attr_reader :data, :fmt
11
+ attr_reader :data
12
12
 
13
13
  # @param data [Hash] data to display, from a response object
14
14
  # @param keys [Array[Symbol]] keys to display, in order
@@ -18,32 +18,48 @@ module WavefrontDisplayPrinter
18
18
  @fmt = format_string(data, keys)
19
19
  end
20
20
 
21
+ # @return [String] used to format output
22
+ #
21
23
  def format_string(data, keys)
22
24
  keys.map { |k| "%-#{data.longest_value_of(k)}<#{k}>s" }.join(' ')
23
25
  end
24
26
 
27
+ # Flatten nested data.
28
+ # @param data [Map,Hash] data to flatten
29
+ # @param keys [Array[Symbol]] keys of interest. We don't bother working on
30
+ # things we'll only throw away
31
+ #
25
32
  def stringify(data, keys)
26
- data.map { |e| e.tap { keys.each { |k| e[k] = to_string(e[k]) } } }
33
+ data.map { |e| e.tap { keys.each { |k| e[k] = value_as_string(e[k]) } } }
27
34
  end
28
35
 
29
- def to_string(value)
30
- if value.is_a?(Array)
31
- value.join(', ')
32
- elsif value.is_a?(Map)
33
- map_to_string(value)
34
- else
35
- value
36
- end
36
+ # Turn a (potentially) more complicated structure into a string
37
+ # @param value [Object]
38
+ # @return [String]
39
+ #
40
+ def value_as_string(value)
41
+ return value.join(', ') if value.is_a?(Array)
42
+
43
+ return map_to_string(value) if value.is_a?(Map)
44
+
45
+ value
37
46
  end
38
47
 
48
+ # If we get a hash as a value (tags, for instance) we squash it down to a
49
+ # "key1=val1;key2=val2" kind of string. Note that this doesn't handle
50
+ # nested hashes. It shouldn't have to.
51
+ #
52
+ # @param value [Map,Hash] { k1: 'v1', k2: 'v2' }
53
+ # @return [String] 'k1=v1;k2=v2'
54
+ #
39
55
  def map_to_string(value)
40
- format('%<key>s=%<value>s',
41
- key: value.keys[0],
42
- value: value.values.join(','))
56
+ value.map { |k, v| "#{k}=#{v}" }.join(';')
43
57
  end
44
58
 
59
+ # Format every element according to the format string @fmt
60
+ #
45
61
  def to_s
46
- data.map { |e| format(fmt, e).rstrip }.join("\n")
62
+ data.map { |e| format(@fmt, e).rstrip }.join("\n")
47
63
  rescue KeyError
48
64
  raise WavefrontCli::Exception::UserError, 'field not found'
49
65
  end
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- WF_CLI_VERSION = '4.4.1'
3
+ WF_CLI_VERSION = '4.4.2'
@@ -17,7 +17,7 @@ class WavefrontDisplayPrinterTerse < MiniTest::Test
17
17
  @wf = WavefrontDisplayPrinter::Terse.new(TERSE_DATA, %i[id name])
18
18
  end
19
19
 
20
- def test_fmt
20
+ def test_format_string
21
21
  assert_equal('%-3<id>s', wf.format_string(TERSE_DATA, [:id]))
22
22
  assert_equal('%-3<id>s %-5<name>s',
23
23
  wf.format_string(TERSE_DATA, %i[id name]))
@@ -45,12 +45,19 @@ class WavefrontDisplayPrinterTerse < MiniTest::Test
45
45
  [:things]))
46
46
  end
47
47
 
48
- def test_to_string
49
- assert_equal('a, b, c', wf.to_string(%w[a b c]))
50
- assert_equal('abc', wf.to_string('abc'))
48
+ def test_map_to_string
49
+ assert_equal('key1=value1;key2=value2;key3=value3',
50
+ wf.map_to_string(key1: 'value1',
51
+ key2: 'value2',
52
+ key3: 'value3'))
51
53
  end
52
54
 
53
- def test_end_to_end
55
+ def test_value_as_string
56
+ assert_equal('a, b, c', wf.value_as_string(%w[a b c]))
57
+ assert_equal('abc', wf.value_as_string('abc'))
58
+ end
59
+
60
+ def test_end_to_end_1
54
61
  input, expected = OutputTester.new.in_and_out('alerts-input.json',
55
62
  'alerts-human-terse')
56
63
  out = WavefrontDisplayPrinter::Terse.new(input, %i[id status name]).to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher