wavefront-cli 2.8.0 → 2.9.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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -0
  3. data/HISTORY.md +17 -0
  4. data/Rakefile +1 -1
  5. data/bin/wf +1 -1
  6. data/lib/wavefront-cli/base.rb +46 -18
  7. data/lib/wavefront-cli/base_write.rb +49 -33
  8. data/lib/wavefront-cli/commands/.rubocop.yml +7 -0
  9. data/lib/wavefront-cli/commands/alert.rb +0 -1
  10. data/lib/wavefront-cli/commands/base.rb +1 -1
  11. data/lib/wavefront-cli/commands/link.rb +5 -0
  12. data/lib/wavefront-cli/commands/window.rb +1 -0
  13. data/lib/wavefront-cli/commands/write.rb +1 -1
  14. data/lib/wavefront-cli/controller.rb +51 -21
  15. data/lib/wavefront-cli/derivedmetric.rb +4 -0
  16. data/lib/wavefront-cli/display/alert.rb +2 -0
  17. data/lib/wavefront-cli/display/base.rb +18 -11
  18. data/lib/wavefront-cli/display/metric.rb +13 -5
  19. data/lib/wavefront-cli/display/printer/long.rb +12 -8
  20. data/lib/wavefront-cli/display/printer/sparkline.rb +2 -2
  21. data/lib/wavefront-cli/display/printer/terse.rb +3 -1
  22. data/lib/wavefront-cli/display/query.rb +7 -3
  23. data/lib/wavefront-cli/display/write.rb +2 -0
  24. data/lib/wavefront-cli/event.rb +27 -16
  25. data/lib/wavefront-cli/exception.rb +8 -0
  26. data/lib/wavefront-cli/externallink.rb +30 -0
  27. data/lib/wavefront-cli/maintenancewindow.rb +2 -2
  28. data/lib/wavefront-cli/output/hcl/base.rb +21 -18
  29. data/lib/wavefront-cli/output/hcl/dashboard.rb +13 -38
  30. data/lib/wavefront-cli/output/hcl/notificant.rb +4 -2
  31. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +22 -0
  32. data/lib/wavefront-cli/output/hcl/stdlib/string.rb +9 -0
  33. data/lib/wavefront-cli/output/wavefront/base.rb +3 -0
  34. data/lib/wavefront-cli/output/wavefront/query.rb +2 -2
  35. data/lib/wavefront-cli/query.rb +2 -0
  36. data/lib/wavefront-cli/report.rb +5 -2
  37. data/lib/wavefront-cli/{string.rb → stdlib/string.rb} +16 -12
  38. data/lib/wavefront-cli/version.rb +1 -1
  39. data/lib/wavefront-cli/write.rb +12 -4
  40. data/spec/spec_helper.rb +41 -24
  41. data/spec/wavefront-cli/commands/link_spec.rb +1 -1
  42. data/spec/wavefront-cli/derivedmetric_spec.rb +2 -2
  43. data/spec/wavefront-cli/display/base_spec.rb +2 -0
  44. data/spec/wavefront-cli/display/printer/long_spec.rb +1 -0
  45. data/spec/wavefront-cli/externallink_spec.rb +52 -4
  46. data/spec/wavefront-cli/output/hcl_spec.rb +3 -1
  47. data/spec/wavefront-cli/output/ruby_spec.rb +5 -5
  48. data/spec/wavefront-cli/output/wavefront/query_spec.rb +14 -9
  49. data/spec/wavefront-cli/output/wavefront_spec.rb +3 -1
  50. data/spec/wavefront-cli/query_spec.rb +2 -0
  51. data/spec/wavefront-cli/{string_spec.rb → stdlib/string_spec.rb} +3 -3
  52. data/wavefront-cli.gemspec +7 -7
  53. metadata +34 -30
@@ -14,6 +14,7 @@ class WavefrontCommandWindow < WavefrontCommandBase
14
14
  def sdk_class
15
15
  'MaintenanceWindow'
16
16
  end
17
+
17
18
  def _commands
18
19
  ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
19
20
  "describe #{CMN} [-f format] <id>",
@@ -11,7 +11,7 @@ class WavefrontCommandWrite < WavefrontCommandBase
11
11
  ['point [-DnViq] [-c file] [-P profile] [-E proxy] [-t time] ' \
12
12
  '[-p port] [-H host] [-T tag...] <metric> <value>',
13
13
  'file [-DnViq] [-c file] [-P profile] [-E proxy] [-H host] ' \
14
- '[-p port] [-F format] [-m metric] [-T tag...] <file>']
14
+ '[-p port] [-F infileformat] [-m metric] [-T tag...] <file>']
15
15
  end
16
16
 
17
17
  def _options
@@ -31,8 +31,8 @@ class WavefrontCliController
31
31
  cmd, opts = parse_args
32
32
  @opts = parse_opts(opts)
33
33
  pp @opts if @opts[:debug]
34
- hook = load_sdk(cmd, @opts)
35
- run_command(hook)
34
+ cli_class_obj = load_cli_class(cmd, @opts)
35
+ run_command(cli_class_obj)
36
36
  end
37
37
 
38
38
  # What you see when you do 'wf --help'
@@ -57,6 +57,7 @@ class WavefrontCliController
57
57
  # Parse the input. The first Docopt.docopt handles the default
58
58
  # options, the second works on the command.
59
59
  #
60
+ # rubocop:disable Metrics/AbcSize
60
61
  def parse_args
61
62
  Docopt.docopt(usage[:default], version: WF_CLI_VERSION, argv: args)
62
63
  rescue Docopt::Exit => e
@@ -72,34 +73,61 @@ class WavefrontCliController
72
73
  abort e.message
73
74
  end
74
75
  end
76
+ # rubocop:enable Metrics/AbcSize
75
77
 
76
- def parse_opts(o)
77
- WavefrontCli::OptHandler.new(o).opts
78
+ def parse_opts(options)
79
+ WavefrontCli::OptHandler.new(options).opts
78
80
  end
79
81
 
80
- # Get the SDK class we need to run the command we've been given.
82
+ # Get the CLI class we need to run the command we've been given.
81
83
  #
82
84
  # @param cmd [String]
83
- def load_sdk(cmd, opts)
85
+ # @return WavefrontCli::cmd
86
+ #
87
+ # rubocop:disable Metrics/AbcSize
88
+ def load_cli_class(cmd, opts)
84
89
  require_relative File.join('.', cmds[cmd].sdk_file)
85
90
  Object.const_get('WavefrontCli').const_get(cmds[cmd].sdk_class).new(opts)
86
91
  rescue WavefrontCli::Exception::UnhandledCommand
87
- abort 'Fatal error. Unsupported command.'
88
- rescue StandardError => e
89
- p e
92
+ abort 'Fatal error. Unsupported command. Please open a Github issue.'
93
+ rescue WavefrontCli::Exception::InvalidInput => e
94
+ abort "Invalid input. #{e.message}"
95
+ rescue RuntimeError => e
96
+ abort "Unable to run command. #{e.message}."
90
97
  end
91
-
92
- def run_command(hook)
93
- hook.validate_opts
94
- hook.run
98
+ # rubocop:enable Metrics/AbcSize
99
+
100
+ # rubocop:disable Metrics/AbcSize
101
+ # rubocop:disable Metrics/MethodLength
102
+ def run_command(cli_class_obj)
103
+ cli_class_obj.validate_opts
104
+ cli_class_obj.run
105
+ rescue WavefrontCli::Exception::CredentialError => e
106
+ abort "Credential error. #{e.message}"
95
107
  rescue WavefrontCli::Exception::UnsupportedOutput => e
96
108
  abort e.message
109
+ rescue WavefrontCli::Exception::InsufficientData => e
110
+ abort "Insufficient data. #{e.message}"
111
+ rescue WavefrontCli::Exception::UnsupportedFileFormat
112
+ abort 'Unsupported file format.'
113
+ rescue WavefrontCli::Exception::UnparseableInput => e
114
+ abort "Cannot parse input. #{e.message}"
115
+ rescue WavefrontCli::Exception::FileNotFound
116
+ abort 'File not found.'
117
+ rescue WavefrontCli::Exception::UnparseableInput
118
+ abort 'Cannot parse input.'
119
+ rescue WavefrontCli::Exception::SystemError => e
120
+ abort "Host system error. #{e.message}"
121
+ rescue WavefrontCli::Exception::UnsupportedOperation => e
122
+ abort "Unsupported operation.\n#{e.message}"
97
123
  rescue StandardError => e
98
- $stderr.puts "general error: #{e}"
99
- $stderr.puts "re-run with '-D' for stack trace." unless opts[:debug]
100
- $stderr.puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" if opts[:debug]
124
+ warn "general error: #{e}"
125
+ warn "re-run with '-D' for stack trace." unless opts[:debug]
126
+ warn "Backtrace:\n\t#{e.backtrace.join("\n\t")}" if opts[:debug]
101
127
  abort
102
128
  end
129
+ # rubocop:enable Metrics/MethodLength
130
+ # rubocop:enable Metrics/AbcSize
103
131
 
104
132
  # Each command is defined in its own file. Dynamically load all
105
133
  # those commands.
@@ -117,9 +145,9 @@ class WavefrontCliController
117
145
  # @param f [Pathname] path of file to load
118
146
  # return [Class] new class object defining command.
119
147
  #
120
- def import_command(f)
121
- return if f.extname != '.rb' || f.basename.to_s == 'base.rb'
122
- k_name = f.basename.to_s[0..-4]
148
+ def import_command(path)
149
+ return if path.extname != '.rb' || path.basename.to_s == 'base.rb'
150
+ k_name = path.basename.to_s[0..-4]
123
151
  require(CMD_DIR + k_name)
124
152
  Object.const_get("WavefrontCommand#{k_name.capitalize}").new
125
153
  end
@@ -129,7 +157,9 @@ class WavefrontCliController
129
157
  # @param h [Hash] options hash
130
158
  # return [Hash] h with modified keys
131
159
  #
132
- def sanitize_keys(h)
133
- h.each_with_object({}) { |(k, v), r| r[k.to_s.delete('-').to_sym] = v }
160
+ def sanitize_keys(options)
161
+ options.each_with_object({}) do |(k, v), r|
162
+ r[k.to_s.delete('-').to_sym] = v
163
+ end
134
164
  end
135
165
  end
@@ -13,6 +13,7 @@ module WavefrontCli
13
13
  wf.describe(options[:'<id>'], options[:version])
14
14
  end
15
15
 
16
+ # rubocop:disable Metrics/AbcSize
16
17
  def do_delete
17
18
  word = if wf.describe(options[:'<id>']).status.code == 200
18
19
  'Soft'
@@ -25,6 +26,7 @@ module WavefrontCli
25
26
 
26
27
  wf.delete(options[:'<id>'])
27
28
  end
29
+ # rubocop:enable Metrics/AbcSize
28
30
 
29
31
  def do_history
30
32
  wf.history(options[:'<id>'])
@@ -34,6 +36,7 @@ module WavefrontCli
34
36
  wf.create(build_body)
35
37
  end
36
38
 
39
+ # rubocop:disable Metrics/AbcSize
37
40
  def build_body
38
41
  ret = { query: options[:'<query>'],
39
42
  name: options[:'<name>'],
@@ -45,6 +48,7 @@ module WavefrontCli
45
48
  ret[:tags] = options[:ctag] if valid_tags?
46
49
  ret
47
50
  end
51
+ # rubocop:enable Metrics/AbcSize
48
52
 
49
53
  def valid_tags?
50
54
  !options[:ctag].empty? && validate_tags(options[:ctag])
@@ -48,10 +48,12 @@ module WavefrontDisplay
48
48
  puts "Unsnoozed alert '#{options[:'<id>']}'."
49
49
  end
50
50
 
51
+ # rubocop:disable Metrics/AbcSize
51
52
  def do_summary
52
53
  kw = data.keys.map(&:size).max + 2
53
54
  data.delete_if { |_k, v| v.zero? } unless options[:all]
54
55
  data.sort.each { |k, v| puts format("%-#{kw}s%s", k, v) }
55
56
  end
57
+ # rubocop:enable Metrics/AbcSize
56
58
  end
57
59
  end
@@ -118,17 +118,20 @@ module WavefrontDisplay
118
118
 
119
119
  # if this is a section of a larger dataset, say so
120
120
  #
121
+ # rubocop:disable Metrics/AbcSize
121
122
  def pagination_line
122
- if raw.respond_to?(:moreItems) && raw.moreItems == true
123
- if raw.respond_to?(:offset) && raw.respond_to?(:limit)
124
- enditem = raw.limit > 0 ? raw.offset + raw.limit - 1 : 0
125
- puts format('List shows items %d to %d. Use -o and -L for more.',
126
- raw.offset, enditem)
127
- else
128
- puts 'List shows paginated output. Use -o and -L for more.'
129
- end
123
+ return unless raw.respond_to?(:moreItems) && raw.moreItems == true
124
+
125
+ if raw.respond_to?(:offset) && raw.respond_to?(:limit)
126
+ puts 'List shows paginated output. Use -o and -L for more.'
127
+ return
130
128
  end
129
+
130
+ enditem = raw.limit > 0 ? raw.offset + raw.limit - 1 : 0
131
+ puts format('List shows items %d to %d. Use -o and -L for more.',
132
+ raw.offset, enditem)
131
133
  end
134
+ # rubocop:enable Metrics/AbcSize
132
135
 
133
136
  # Give it a key-value hash, and it will return the size of the first
134
137
  # column to use when formatting that data.
@@ -264,9 +267,10 @@ module WavefrontDisplay
264
267
  # used for unit tests.
265
268
  # return [String] a human-readable timestamp
266
269
  #
267
- def human_time(t, force_utc = false)
268
- raise ArgumentError unless t.is_a?(Numeric) || t.is_a?(String)
269
- str = t.to_s
270
+ # rubocop:disable Metrics/MethodLength
271
+ def human_time(time, force_utc = false)
272
+ raise ArgumentError unless time.is_a?(Numeric) || time.is_a?(String)
273
+ str = time.to_s
270
274
 
271
275
  if str =~ /^\d{13}$/
272
276
  fmt = '%Q'
@@ -278,9 +282,12 @@ module WavefrontDisplay
278
282
  raise ArgumentError
279
283
  end
280
284
 
285
+ # rubocop:disable Style/DateTime
281
286
  ret = DateTime.strptime(str, fmt).to_time
287
+ # rubocop:enable Style/DateTime
282
288
  ret = ret.utc if force_utc
283
289
  ret.strftime(out_fmt)
284
290
  end
291
+ # rubocop:enable Metrics/MethodLength
285
292
  end
286
293
  end
@@ -6,16 +6,24 @@ module WavefrontDisplay
6
6
  #
7
7
  class Metric < Base
8
8
  def do_describe
9
- if data.empty? || data.hosts.empty?
10
- puts 'No matches.'
11
- exit
12
- end
9
+ bail_out if no_data
13
10
 
14
11
  @data = data['hosts'].map do |h, _aggr|
15
12
  { host: h[:host], last_update: human_time(h[:last_update]) }
16
- end.sort_by { |h| h[:last_update] }.reverse
13
+ end
14
+
15
+ @data.sort_by { |h| h[:last_update] }.reverse
17
16
 
18
17
  multicolumn(:host, :last_update)
19
18
  end
19
+
20
+ def no_data?
21
+ data.empty? || data.hosts.empty?
22
+ end
23
+
24
+ def bail_out
25
+ puts 'No matches.'
26
+ exit
27
+ end
20
28
  end
21
29
  end
@@ -1,5 +1,5 @@
1
1
  require_relative 'base'
2
- require_relative '../../string'
2
+ require_relative '../../stdlib/string'
3
3
 
4
4
  module WavefrontDisplayPrinter
5
5
  #
@@ -27,11 +27,12 @@ module WavefrontDisplayPrinter
27
27
  # @kw [Integer] the width of the first (key) column.
28
28
  # @returns [Nil]
29
29
  #
30
- def _two_columns(data, kw = nil, fields = nil)
30
+ # rubocop:disable Metrics/AbcSize
31
+ def _two_columns(data, key_col_width = nil, fields = nil)
31
32
  [data].flatten.each do |item|
32
33
  preen_fields(item, fields)
33
- kw = key_width(item) unless kw
34
- @kw = kw unless @kw
34
+ key_col_width ||= key_width(item)
35
+ @kw ||= key_col_width
35
36
  mk_indent(indent)
36
37
  item.each { |k, v| parse_line(k, v) }
37
38
  add_line(nil) if indent.zero?
@@ -41,6 +42,7 @@ module WavefrontDisplayPrinter
41
42
  @kw += 2
42
43
  mk_indent(indent)
43
44
  end
45
+ # rubocop:enable Metrics/AbcSize
44
46
 
45
47
  # Drop any fields not required.
46
48
  #
@@ -149,8 +151,8 @@ module WavefrontDisplayPrinter
149
151
  # Add a horizontal rule, from the start of the second column to
150
152
  # just shy of the end of the terminal
151
153
  #
152
- def add_rule(kw)
153
- add_line(nil, '-' * (TW - kw - 4))
154
+ def add_rule(key_col_width)
155
+ add_line(nil, '-' * (TW - key_col_width - 4))
154
156
  end
155
157
 
156
158
  # Make the string which is prepended to each line. Stepping is
@@ -170,12 +172,14 @@ module WavefrontDisplayPrinter
170
172
  # @param val [String, Numeric] what to print in the second column
171
173
  # @param tw [Integer] terminal width
172
174
  #
173
- def mk_line(key, value = '', tw = TW)
175
+ # rubocop:disable Metrics/AbcSize
176
+ def mk_line(key, value = '', term_width = TW)
174
177
  return indent_str + ' ' * kw + value if !key || key.empty?
175
178
 
176
179
  indent_str + format("%-#{kw}s%s", key, value)
177
- .fold(tw, kw + indent_str.size, '').rstrip
180
+ .fold(term_width, kw + indent_str.size, '').rstrip
178
181
  end
182
+ # rubocop:enable Metrics/AbcSize
179
183
 
180
184
  # Add a line, prepped by #mk_line() to the out array.
181
185
  #
@@ -21,8 +21,8 @@ class WavefrontSparkline
21
21
  # the given range. The `rescue` clause handles occasions when
22
22
  # Wavefront returns NaN as a value, or if the range is zero.
23
23
  #
24
- def sized_block(v, range)
25
- BLOCKS[(v / range * (BLOCKS.length - 1)).floor]
24
+ def sized_block(val, range)
25
+ BLOCKS[(val / range * (BLOCKS.length - 1)).floor]
26
26
  rescue StandardError
27
27
  BLOCKS.first
28
28
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'base'
2
2
 
3
3
  module WavefrontDisplayPrinter
4
-
4
+ #
5
5
  # Print things which are per-row. The terse listings, primarily
6
6
  #
7
7
  class Terse < Base
@@ -26,6 +26,7 @@ module WavefrontDisplayPrinter
26
26
  #
27
27
  # @return [Hash] with the same keys as :keys and Integer values
28
28
  #
29
+ # rubocop:disable Metrics/AbcSize
29
30
  def longest_keys
30
31
  keys.each_with_object(Hash[*keys.map { |k| [k, 0] }.flatten]) \
31
32
  do |k, aggr|
@@ -37,6 +38,7 @@ module WavefrontDisplayPrinter
37
38
  end
38
39
  end
39
40
  end
41
+ # rubocop:enable Metrics/AbcSize
40
42
 
41
43
  # Print multiple column output. This method does no word
42
44
  # wrapping.
@@ -6,6 +6,7 @@ module WavefrontDisplay
6
6
  # Format human-readable output for queries.
7
7
  #
8
8
  class Query < Base
9
+ # rubocop:disable Metrics/AbcSize
9
10
  def do_default
10
11
  d_obj = { name: data.name,
11
12
  query: data.query,
@@ -19,14 +20,15 @@ module WavefrontDisplay
19
20
  @data = d_obj
20
21
  long_output
21
22
  end
23
+ # rubocop:enable Metrics/AbcSize
22
24
 
23
25
  def mk_timeseries(data)
24
- return [] unless data.key?(:timeseries)
26
+ return [] unless data.key?(:timeseries)
25
27
 
26
28
  data[:timeseries].each do |s|
27
29
  unless options[:nospark]
28
30
  s[:sparkline] = WavefrontSparkline.new(s[:data]).sparkline
29
- s.reorder!({label: nil, sparkline: nil})
31
+ s.reorder!(label: nil, sparkline: nil)
30
32
  end
31
33
 
32
34
  s[:data] = humanize_series(s[:data])
@@ -54,7 +56,7 @@ module WavefrontDisplay
54
56
  if data.empty?
55
57
  puts 'No aliases defined.'
56
58
  else
57
- data.each { |k, _v| puts k.to_s[2..-1] }
59
+ data.each_key { |k| puts k.to_s[2..-1] }
58
60
  end
59
61
  end
60
62
 
@@ -67,6 +69,7 @@ module WavefrontDisplay
67
69
  data
68
70
  end
69
71
 
72
+ # rubocop:disable Metrics/MethodLength
70
73
  def humanize_series(data)
71
74
  last_date = nil
72
75
 
@@ -84,6 +87,7 @@ module WavefrontDisplay
84
87
  last_date = date
85
88
  format('%-12s %s %s', ds, time, val)
86
89
  end
90
+ # rubocop:enable Metrics/MethodLength
87
91
  end
88
92
  end
89
93
  end
@@ -4,10 +4,12 @@ module WavefrontDisplay
4
4
  # Format human-readable output when writing points.
5
5
  #
6
6
  class Write < Base
7
+ # rubocop:disable Metrics/AbcSize
7
8
  def do_point
8
9
  report unless options[:quiet] || (data[:unsent] + data[:rejected] > 0)
9
10
  exit(data.rejected.zero? && data.unsent.zero? ? 0 : 1)
10
11
  end
12
+ # rubocop:enable Metrics/AbcSize
11
13
 
12
14
  def do_file
13
15
  do_point
@@ -1,14 +1,15 @@
1
1
  require 'fileutils'
2
+ require 'open3'
2
3
  require 'wavefront-sdk/mixins'
3
4
  require_relative 'base'
4
- require 'open3'
5
5
 
6
6
  EVENT_STATE_DIR = Pathname.new('/var/tmp/wavefront')
7
+
7
8
  module WavefrontCli
8
9
  #
9
10
  # CLI coverage for the v2 'event' API.
10
11
  #
11
- class Event < WavefrontCli::Base
12
+ class Event < Base
12
13
  attr_reader :state_dir
13
14
  include Wavefront::Mixins
14
15
 
@@ -32,7 +33,7 @@ module WavefrontCli
32
33
  # You can override the options generated by docopt. This is how
33
34
  # #wrap() works.
34
35
  #
35
- # rubocop:disable Metrics/CyclomaticComplexity
36
+ # rubocop:disable Metrics/AbcSize
36
37
  def do_create(opts = nil)
37
38
  opts ||= options
38
39
 
@@ -50,6 +51,7 @@ module WavefrontCli
50
51
 
51
52
  resp
52
53
  end
54
+ # rubocop:enable Metrics/AbcSize
53
55
 
54
56
  # The user doesn't have to give us an event ID. If no event
55
57
  # name is given, we'll pop the last event off the stack. If an
@@ -57,6 +59,7 @@ module WavefrontCli
57
59
  # name, we'll look for something on the stack. If it does look
58
60
  # like a real event, we'll make and API call straight away.
59
61
  #
62
+ # rubocop:disable Metrics/AbcSize
60
63
  def do_close(id = nil)
61
64
  id ||= options[:'<id>']
62
65
  ev_file = id =~ /^\d{13}:.+/ ? state_dir + id : nil
@@ -68,6 +71,7 @@ module WavefrontCli
68
71
  ev_file.unlink if ev_file && ev_file.exist? && res.status.code == 200
69
72
  res
70
73
  end
74
+ # rubocop:enable Metrics/AbcSize
71
75
 
72
76
  def do_show
73
77
  events = local_event_list
@@ -95,6 +99,10 @@ module WavefrontCli
95
99
 
96
100
  # return [Hash] body for #create() method
97
101
  #
102
+ # rubocop:disable Metrics/AbcSize
103
+ # rubocop:disable Metrics/CyclomaticComplexity
104
+ # rubocop:disable Metrics/PerceivedComplexity
105
+ # rubocop:disable Metrics/MethodLength
98
106
  def create_body(opts, t_start)
99
107
  body = { name: opts[:'<event>'],
100
108
  startTime: t_start,
@@ -114,6 +122,10 @@ module WavefrontCli
114
122
 
115
123
  body
116
124
  end
125
+ # rubocop:enable Metrics/MethodLength
126
+ # rubocop:enable Metrics/CyclomaticComplexity
127
+ # rubocop:enable Metrics/PerceivedComplexity
128
+ # rubocop:enable Metrics/AbcSize
117
129
 
118
130
  # @return a local event from the stack directory
119
131
  #
@@ -130,15 +142,14 @@ module WavefrontCli
130
142
  def local_event_list
131
143
  state_dir.children
132
144
  rescue Errno::ENOENT
133
- raise 'There is no event state directory on this host.'
145
+ raise(WavefrontCli::Exception::SystemError,
146
+ 'There is no event state directory on this host.')
134
147
  end
135
148
 
136
149
  # Run a command, stream stderr and stdout to the screen (they
137
150
  # get combined -- could be an issue for someone somewhere) and
138
151
  # return the command's exit code
139
152
  #
140
- # rubocop:disable Lint/AssignmentInCondition
141
- #
142
153
  def run_wrapped_cmd(cmd)
143
154
  separator = '-' * (TW - 4)
144
155
 
@@ -146,7 +157,9 @@ module WavefrontCli
146
157
  ret = nil
147
158
 
148
159
  Open3.popen2e(cmd) do |_in, out, thr|
160
+ # rubocop:disable Lint/AssignmentInCondition
149
161
  while l = out.gets do STDERR.puts(l) end
162
+ # rubocop:enable Lint/AssignmentInCondition
150
163
  ret = thr.value.exitstatus
151
164
  end
152
165
 
@@ -160,21 +173,19 @@ module WavefrontCli
160
173
  #
161
174
  def create_state_file(id, hosts = [])
162
175
  fname = state_dir + id
163
-
164
- begin
165
- File.open(fname, 'w') { hosts.to_s }
166
- rescue StandardError
167
- raise 'Event was created but state file was not.'
168
- end
169
-
176
+ File.open(fname, 'w') { hosts.to_s }
170
177
  puts "Event state recorded at #{fname}."
178
+ rescue StandardError
179
+ puts 'NOTICE: event was created but state file was not.'
171
180
  end
172
181
 
173
182
  def create_state_dir
174
183
  FileUtils.mkdir_p(state_dir)
175
- return true if state_dir.exist? && state_dir.directory? &&
176
- state_dir.writable?
177
- raise 'Cannot create state directory.'
184
+ raise unless state_dir.exist? && state_dir.directory? &&
185
+ state_dir.writable?
186
+ rescue StandardError
187
+ raise(WavefrontCli::Exception::SystemError,
188
+ "Cannot create writable system directory at '#{state_dir}'.")
178
189
  end
179
190
 
180
191
  def validate_input