From 176d06ea4f5f6e3b6cd704f56793d239595c7008 Mon Sep 17 00:00:00 2001 From: Reid Vandewiele Date: Tue, 1 Aug 2017 11:16:44 -0700 Subject: [PATCH] Make unsupplied optional values clearer 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. --- files/amq_metrics | 10 +++++----- files/tk_metrics | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/files/amq_metrics b/files/amq_metrics index e689554..a5d0d2c 100644 --- a/files/amq_metrics +++ b/files/amq_metrics @@ -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) @@ -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 @@ -140,7 +140,7 @@ 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| diff --git a/files/tk_metrics b/files/tk_metrics index e4aaf07..ba62a8e 100644 --- a/files/tk_metrics +++ b/files/tk_metrics @@ -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) @@ -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 @@ -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| @@ -199,7 +199,7 @@ 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|