Skip to content

Commit

Permalink
Make unsupplied optional values clearer
Browse files Browse the repository at this point in the history
Previously some optional values had a default value of False. In order
to indicate that the user doesn't need to supply a value a default is
required, but False as the default did not make it clear that the value
simply hadn't been supplied.

This commit switches such values to use :undef as their default instead,
thus making it clearer what is happening.
  • Loading branch information
reidmv committed Aug 1, 2017
1 parent 5784aae commit 1fb4fb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions files/amq_metrics
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ OptionParser.new do |parser|
end

# Each possible configuration option is defined here
option.call(:config, 'Path to configuration file', opt_value, save_ident, false)
option.call(:"output-dir", 'Directory to save output to', opt_value, save_ident, false)
option.call(:config, 'Path to configuration file', opt_value, save_ident, :undef)
option.call(:"output-dir", 'Directory to save output to', opt_value, save_ident, :undef)
option.call(:hosts, 'Hosts to collect metrics from (comma-separated)', opt_value, save_list, ['localhost'])
option.call(:"additional-metrics", 'Additional metrics to collect (comma-separated)', opt_value, save_list, [])
option.call(:"additional-metrics", 'Additional metrics to collect (comma-separated)', opt_value, save_list)
option.call(:"metrics-port", 'The port the metrics service runs on', opt_value, save_ident)
option.call(:clientcert, 'Not used', opt_value, save_ident)
option.call(:"pe-version", 'The version of PE in use', opt_value, save_ident)
Expand All @@ -49,7 +49,7 @@ end.parse!

# If a configuration file has been specified, read additional configuration
# from it.
if from_cli[:config]
unless :undef == from_cli[:config]
begin
from_file = YAML.load_file(from_cli[:config])
rescue Exception => e
Expand Down Expand Up @@ -140,15 +140,15 @@ config[:hosts].each do |host|

json_dataset = JSON.pretty_generate(dataset)

if config[:"output-dir"] then
unless :undef == config[:"output-dir"]
Dir.chdir(config[:"output-dir"]) do
Dir.mkdir(host) unless File.exist?(host)
File.open(File.join(host, filename), 'w') do |file|
file.write(json_dataset)
end
end
end
if config[:print] then
if config[:print]
STDOUT.write(json_dataset)
end
rescue Exception => e
Expand Down
14 changes: 7 additions & 7 deletions files/tk_metrics
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ OptionParser.new do |parser|
end

# Each possible configuration option is defined here
option.call(:config, 'Path to configuration file', opt_value, save_ident, false)
option.call(:"output-dir", 'Directory to save output to', opt_value, save_ident, false)
option.call(:config, 'Path to configuration file', opt_value, save_ident, :undef)
option.call(:"output-dir", 'Directory to save output to', opt_value, save_ident, :undef)
option.call(:hosts, 'Hosts to collect metrics from (comma-separated)', opt_value, save_list, ['localhost'])
option.call(:"additional-metrics", 'Additional metrics to collect (comma-separated)', opt_value, save_list, [])
option.call(:"additional-metrics", 'Additional metrics to collect (comma-separated)', opt_value, save_list, :undef)
option.call(:"metrics-port", 'The port the metrics service runs on', opt_value, save_ident)
option.call(:clientcert, 'Not used', opt_value, save_ident)
option.call(:"pe-version", 'The version of PE in use', opt_value, save_ident)
Expand All @@ -49,7 +49,7 @@ end.parse!

# If a configuration file has been specified, read additional configuration
# from it.
if from_cli[:config]
unless :undef == from_cli[:config]
begin
from_file = YAML.load_file(from_cli[:config])
rescue Exception => e
Expand Down Expand Up @@ -181,7 +181,7 @@ config[:hosts].each do |host|
status_output = get_status_endpoint(host, config[:"metrics-port"], config[:ssl])
dataset['servers'][hostkey] = {config[:"metrics-type"] => status_output}

unless config[:"additional-metrics"].empty? then
unless :undef == config[:"additional-metrics"]
metrics_array = retrieve_additional_metrics(host, config[:"metrics-port"], config[:"additional-metrics"], config[:"pe-version"], config[:ssl])

metrics_array.each do |metric_hash|
Expand All @@ -199,15 +199,15 @@ config[:hosts].each do |host|

json_dataset = JSON.pretty_generate(dataset)

unless config[:"output-dir"] == false then
unless :undef == config[:"output-dir"]
Dir.chdir(config[:"output-dir"]) do
Dir.mkdir(host) unless File.exist?(host)
File.open(File.join(host, filename), 'w') do |file|
file.write(json_dataset)
end
end
end
if config[:print] != false then
if config[:print]
STDOUT.write(json_dataset)
end
end
Expand Down

0 comments on commit 1fb4fb5

Please sign in to comment.