wavefront-cli 4.0.1 → 4.0.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: 5ef777d9892feec5a1f016e2a1129826735181bd3ce15a6a83942743606be0e9
4
- data.tar.gz: dd49d2872f08535cf2dfe5d0f3780b80cdeea956827acfd817445819de7dcb78
3
+ metadata.gz: 83528e35b66e2a098928edb63b4f62cf4f730153caf886e8d2132dd8ef870340
4
+ data.tar.gz: 9a6affc13f2b2fc1c41052abbd25dae47c2412a7bd70b39ec84ab8516ee748fa
5
5
  SHA512:
6
- metadata.gz: 91ecc6b341a68759e76e5ec95f694873cd9f8b88cd1bae3a40b2a354c9dd9952550f185c43211475fe146f2ab00446c61e364cef02c4bb1921d56f1ff0c173b1
7
- data.tar.gz: 881eba75e3660ae2a0550f946c0324337e410340693821f0ce581a62ef6d29ce7fbb6437d97d9ba427ba4fa27a754b61c5ef9d75369885e1be01d62bf2a47d64
6
+ metadata.gz: 46710487da70d0ea78ec7ba703b608b634a80d8b837b0ac91d0f4b9efad7a36ede6365060eb3f25455f56fbbdfd55b015a92f87c5c684af86e32f77ed00b038e
7
+ data.tar.gz: d7527a3814e9b2cc8fe1ba1f49fa294122406442e2c5c50ecdafd0f2b6a4a975a2c0c22b74fb01cb5a9379e07977b421d3a526b070714120d2ccfb64f0e59110
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.2 (20/06/2019)
4
+ * Allow importing of dashboards which have a URL but not an ID.
5
+
3
6
  ## 4.0.1 (18/06/2019)
4
7
  * `update` subcommand has been changed to `set`. (Breaking change.)
5
8
  * `import` subcommand now accepts `--update` (`-u`) option, which
@@ -325,7 +325,6 @@ module WavefrontCli
325
325
  # filetype is unknown.
326
326
  # @raise pass through any error loading or parsing the file
327
327
  #
328
- # rubocop:disable Metrics/AbcSize
329
328
  def load_file(path)
330
329
  return load_from_stdin if path == '-'
331
330
 
@@ -333,15 +332,16 @@ module WavefrontCli
333
332
 
334
333
  raise WavefrontCli::Exception::FileNotFound unless file.exist?
335
334
 
336
- if file.extname == '.json'
337
- JSON.parse(IO.read(file))
338
- elsif file.extname == '.yaml' || file.extname == '.yml'
339
- YAML.safe_load(IO.read(file))
335
+ extname = file.extname.downcase
336
+
337
+ if extname == '.json'
338
+ JSON.parse(IO.read(file), symbolize_names: true)
339
+ elsif %w[.yaml .yml].include?(extname)
340
+ YAML.safe_load(IO.read(file), symbolize_names: true)
340
341
  else
341
342
  raise WavefrontCli::Exception::UnsupportedFileFormat
342
343
  end
343
344
  end
344
- # rubocop:enable Metrics/AbcSize
345
345
 
346
346
  # Read STDIN and return a Ruby object, assuming that STDIN is
347
347
  # valid JSON or YAML. This is a dumb method, it does no
@@ -383,8 +383,10 @@ module WavefrontCli
383
383
  wf.describe(options[:'<id>'])
384
384
  end
385
385
 
386
+ # rubocop:disable Metrics/AbcSize
386
387
  def do_import
387
388
  raw = load_file(options[:'<file>'])
389
+ raw = preprocess_rawfile(raw) if respond_to?(:preprocess_rawfile)
388
390
 
389
391
  begin
390
392
  prepped = import_to_create(raw)
@@ -399,9 +401,10 @@ module WavefrontCli
399
401
  wf.create(prepped)
400
402
  end
401
403
  end
404
+ # rubocop:enable Metrics/AbcSize
402
405
 
403
406
  def import_update(raw)
404
- wf.update(raw['id'], raw, false)
407
+ wf.update(raw[:id], raw, false)
405
408
  end
406
409
 
407
410
  def do_delete
@@ -10,7 +10,6 @@ if defined?(DEVELOPMENT)
10
10
  end
11
11
 
12
12
  require 'pathname'
13
- require 'pp'
14
13
  require 'docopt'
15
14
  require_relative 'version'
16
15
  require_relative 'constants'
@@ -34,7 +33,6 @@ class WavefrontCliController
34
33
  @usage = docopt_hash
35
34
  cmd, opts = parse_args
36
35
  @opts = parse_opts(opts)
37
- pp @opts if @opts[:debug]
38
36
  cli_class_obj = load_cli_class(cmd, @opts)
39
37
  run_command(cli_class_obj)
40
38
  end
@@ -144,12 +142,20 @@ class WavefrontCliController
144
142
  abort 'Search on non-existent key. Please use a top-level field.'
145
143
  rescue StandardError => e
146
144
  warn "general error: #{e}"
147
- warn "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
145
+ backtrace_message(e)
148
146
  abort
149
147
  end
150
148
  # rubocop:enable Metrics/MethodLength
151
149
  # rubocop:enable Metrics/AbcSize
152
150
 
151
+ def backtrace_message(err)
152
+ if opts[:debug]
153
+ warn "Backtrace:\n\t#{err.backtrace.join("\n\t")}"
154
+ else
155
+ puts "Re-run command with '-D' for backtrace."
156
+ end
157
+ end
158
+
153
159
  # @param error [WavefrontCli::Exception::CredentialError]
154
160
  #
155
161
  def handle_missing_credentials(error)
@@ -53,5 +53,15 @@ module WavefrontCli
53
53
  wf.unfavorite(options[:'<id>'])
54
54
  do_favs
55
55
  end
56
+
57
+ # Dashboards are, AFAIK, unique in that they do NOT require an
58
+ # ID. They can have a URL instead: the two are equivalent. The
59
+ # easiest workaround for this is to copy the URL to the ID if we
60
+ # only have the former.
61
+ #
62
+ def preprocess_rawfile(raw)
63
+ raw[:id] = raw[:url] if raw.key?(:url) && !raw.key?(:id)
64
+ raw
65
+ end
56
66
  end
57
67
  end
@@ -1 +1 @@
1
- WF_CLI_VERSION = '4.0.1'.freeze
1
+ WF_CLI_VERSION = '4.0.2'.freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt