From 8bcd3d492614270ad056348abd0a565b5000b9ef Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Tue, 2 May 2023 14:37:49 +0000 Subject: [PATCH] Refs #36337 - Remove unused code --- lib/hammer_cli/defaults_commands.rb | 1 - lib/hammer_cli/logger.rb | 4 ++-- lib/hammer_cli/modules.rb | 2 +- lib/hammer_cli/options/normalizers.rb | 2 +- lib/hammer_cli/output/adapter/csv.rb | 1 - lib/hammer_cli/output/formatters.rb | 6 +++--- lib/hammer_cli/ssloptions.rb | 4 ++-- lib/hammer_cli/utils.rb | 12 ------------ test/functional/defaults_test.rb | 1 - test/unit/apipie/option_definition_test.rb | 2 +- test/unit/history_test.rb | 4 ++-- test/unit/logger_test.rb | 4 ++-- test/unit/options/option_definition_test.rb | 4 ++-- test/unit/options/sources/saved_defaults_test.rb | 4 ---- test/unit/output/adapter/abstract_test.rb | 6 +++--- test/unit/output/adapter/csv_test.rb | 12 ++++++------ test/unit/output/adapter/table_test.rb | 10 +++++----- 17 files changed, 30 insertions(+), 49 deletions(-) diff --git a/lib/hammer_cli/defaults_commands.rb b/lib/hammer_cli/defaults_commands.rb index cff5bf66..74df19b1 100644 --- a/lib/hammer_cli/defaults_commands.rb +++ b/lib/hammer_cli/defaults_commands.rb @@ -1,4 +1,3 @@ -require 'hammer_cli' require 'yaml' module HammerCLI class BaseDefaultsProvider diff --git a/lib/hammer_cli/logger.rb b/lib/hammer_cli/logger.rb index b6dc66a4..ee3d9389 100644 --- a/lib/hammer_cli/logger.rb +++ b/lib/hammer_cli/logger.rb @@ -54,7 +54,7 @@ def self.initialize_logger(logger) log_dir = File.expand_path(HammerCLI::Settings.get(:log_dir) || DEFAULT_LOG_DIR) begin FileUtils.mkdir_p(log_dir, :mode => 0750) - rescue Errno::EACCES => e + rescue Errno::EACCES $stderr.puts _("No permissions to create log dir %s.") % log_dir end @@ -68,7 +68,7 @@ def self.initialize_logger(logger) :size => (HammerCLI::Settings.get(:log_size) || 1)*1024*1024) # 1MB # set owner and group (it's ignored if attribute is nil) FileUtils.chown HammerCLI::Settings.get(:log_owner), HammerCLI::Settings.get(:log_group), filename - rescue ArgumentError => e + rescue ArgumentError $stderr.puts _("File %s not writeable, won't log anything to the file!") % filename end diff --git a/lib/hammer_cli/modules.rb b/lib/hammer_cli/modules.rb index 62465091..5501100e 100644 --- a/lib/hammer_cli/modules.rb +++ b/lib/hammer_cli/modules.rb @@ -67,7 +67,7 @@ def self.load!(name) def self.load(name) load! name - rescue Exception => e + rescue Exception false end diff --git a/lib/hammer_cli/options/normalizers.rb b/lib/hammer_cli/options/normalizers.rb index 70e795fc..d542ecd1 100644 --- a/lib/hammer_cli/options/normalizers.rb +++ b/lib/hammer_cli/options/normalizers.rb @@ -298,7 +298,7 @@ def format(val) json_string = ::File.exist?(::File.expand_path(val)) ? super(val) : val ::JSON.parse(json_string) - rescue ::JSON::ParserError => e + rescue ::JSON::ParserError raise ArgumentError, _("Unable to parse JSON input.") end diff --git a/lib/hammer_cli/output/adapter/csv.rb b/lib/hammer_cli/output/adapter/csv.rb index 26f5269e..d6fadbc7 100644 --- a/lib/hammer_cli/output/adapter/csv.rb +++ b/lib/hammer_cli/output/adapter/csv.rb @@ -94,7 +94,6 @@ def initialize(field) @name = nil @prefixes = [] @suffixes = [] - @data end def append_suffix(suffix) diff --git a/lib/hammer_cli/output/formatters.rb b/lib/hammer_cli/output/formatters.rb index 5ff7a2d5..40915d6f 100644 --- a/lib/hammer_cli/output/formatters.rb +++ b/lib/hammer_cli/output/formatters.rb @@ -84,8 +84,8 @@ def required_features tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) } end - def format(data, field_params={}) - c = HighLine.color(data.to_s, @color) + def format(data, _={}) + HighLine.color(data.to_s, @color) end end @@ -97,7 +97,7 @@ def required_features tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) } end - def format(string_date, field_params={}) + def format(string_date, _={}) t = DateTime.parse(string_date.to_s) t.strftime("%Y/%m/%d %H:%M:%S") rescue ArgumentError diff --git a/lib/hammer_cli/ssloptions.rb b/lib/hammer_cli/ssloptions.rb index bf0fad60..710e2372 100644 --- a/lib/hammer_cli/ssloptions.rb +++ b/lib/hammer_cli/ssloptions.rb @@ -68,13 +68,13 @@ def cert_key_options def read_certificate(path) OpenSSL::X509::Certificate.new(File.read(path)) unless path.nil? - rescue SystemCallError => e + rescue SystemCallError warn _("Could't read SSL client certificate %s.") % path end def read_key(path) OpenSSL::PKey.read(File.read(path)) unless path.nil? - rescue SystemCallError => e + rescue SystemCallError warn _("Could't read SSL client key %s.") % path end end diff --git a/lib/hammer_cli/utils.rb b/lib/hammer_cli/utils.rb index bd40112a..dcb94010 100644 --- a/lib/hammer_cli/utils.rb +++ b/lib/hammer_cli/utils.rb @@ -48,18 +48,6 @@ def wrap(line_width: 80, break_sequence: "\n") end end -class Hash - # for ruby < 2.5.0 - def transform_keys - result = {} - each do |key, value| - new_key = yield key - result[new_key] = value - end - result - end -end - module HammerCLI def self.tty? diff --git a/test/functional/defaults_test.rb b/test/functional/defaults_test.rb index bf90353b..d5b046bf 100644 --- a/test/functional/defaults_test.rb +++ b/test/functional/defaults_test.rb @@ -24,7 +24,6 @@ def self.get_defaults(param) let(:cmd) { ['defaults', 'list'] } it 'prints all defaults' do - header = 'Parameter,Value' default_values = { :organization_id => { :value => 3, diff --git a/test/unit/apipie/option_definition_test.rb b/test/unit/apipie/option_definition_test.rb index 5ce02264..98f4a85b 100644 --- a/test/unit/apipie/option_definition_test.rb +++ b/test/unit/apipie/option_definition_test.rb @@ -23,7 +23,7 @@ end - let(:opt2) { HammerCLI::Apipie::OptionDefinition.new("--opt2", "OPT2", "'OPT2'", :referenced_resource => @referenced_resource) } + let(:opt2) { HammerCLI::Apipie::OptionDefinition.new("--opt2", "OPT2", "'OPT2'") } describe "Option Description should be converted" do it "should be converted" do diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index ce22d4fb..5a3aa5e9 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -20,13 +20,13 @@ describe "loading old history" do it "skips loading if the file does not exist" do - history = HammerCLI::ShellHistory.new(new_file.path) + HammerCLI::ShellHistory.new(new_file.path) Readline::HISTORY.to_a.must_equal [] end it "preseeds readline's history" do - history = HammerCLI::ShellHistory.new(history_file.path) + HammerCLI::ShellHistory.new(history_file.path) Readline::HISTORY.to_a.must_equal ["line 1", "line 2"] end diff --git a/test/unit/logger_test.rb b/test/unit/logger_test.rb index 8dff9d15..2ea4bd45 100644 --- a/test/unit/logger_test.rb +++ b/test/unit/logger_test.rb @@ -4,7 +4,7 @@ describe Logging::LogEvent do describe '#initialize_logger' do - let (:logger) { Logging::Logger.new(File.open('/dev/null')) } + let(:logger) { Logging::Logger.new(File.open('/dev/null')) } it "prints message to stderr when log dir can't be created" do log_dir = "/nonexistant/dir/logs" @@ -12,7 +12,7 @@ HammerCLI::Settings.load({:log_dir => log_dir}) - out, err = capture_io do + _, err = capture_io do HammerCLI::Logger::initialize_logger(logger) end diff --git a/test/unit/options/option_definition_test.rb b/test/unit/options/option_definition_test.rb index 99f240a9..f45dff3e 100644 --- a/test/unit/options/option_definition_test.rb +++ b/test/unit/options/option_definition_test.rb @@ -63,7 +63,7 @@ def opt_with_deprecation(deprecation) context = {} cmd = TestDeprecatedOptionCmd.new("", context) - out, err = capture_io { cmd.run(["--another-deprecated=VALUE"]) } + _, err = capture_io { cmd.run(["--another-deprecated=VALUE"]) } err.must_match(/Warning: Option --another-deprecated is deprecated. It is going to be removed/) context[:old_option].must_equal "VALUE" end @@ -72,7 +72,7 @@ def opt_with_deprecation(deprecation) context = {} cmd = TestDeprecatedOptionCmd.new("", context) - out, err = capture_io { cmd.run(["--deprecated=VALUE"]) } + _, err = capture_io { cmd.run(["--deprecated=VALUE"]) } err.must_match(/Warning: Option --deprecated is deprecated. Use --test-option instead/) context[:test_option].must_equal "VALUE" end diff --git a/test/unit/options/sources/saved_defaults_test.rb b/test/unit/options/sources/saved_defaults_test.rb index 1a63b531..9830f920 100644 --- a/test/unit/options/sources/saved_defaults_test.rb +++ b/test/unit/options/sources/saved_defaults_test.rb @@ -20,10 +20,6 @@ @defaults.expects(:get_defaults).with('--test-multi1').returns(:first_value) current_result = {} - expected_result = { - :different_attr_name => 1, - :multiple_switches_option => :first_value - } @logger.expects(:info).with('Custom default value 1 was used for attribute --test') @logger.expects(:info).with('Custom default value first_value was used for attribute --test-multi1') diff --git a/test/unit/output/adapter/abstract_test.rb b/test/unit/output/adapter/abstract_test.rb index f4cd357b..ba3266a7 100644 --- a/test/unit/output/adapter/abstract_test.rb +++ b/test/unit/output/adapter/abstract_test.rb @@ -27,7 +27,7 @@ def required_features it "should filter formatters with incompatible features" do HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [] }) - adapter = adapter_class.new({}, {:type => [UnknownTestFormatter.new]}) + adapter_class.new({}, {:type => [UnknownTestFormatter.new]}) end it "should keep compatible formatters" do @@ -35,7 +35,7 @@ def required_features HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [formatter] }) # set :unknown tag to abstract adapter_class.any_instance.stubs(:features).returns([:unknown]) - adapter = adapter_class.new({}, {:type => [formatter]}) + adapter_class.new({}, {:type => [formatter]}) end it "should put serializers first" do @@ -46,7 +46,7 @@ def required_features HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [formatter2, formatter1] }) # set :unknown tag to abstract adapter_class.any_instance.stubs(:features).returns([:serialized]) - adapter = adapter_class.new({}, {:type => [formatter1, formatter2]}) + adapter_class.new({}, {:type => [formatter1, formatter2]}) end diff --git a/test/unit/output/adapter/csv_test.rb b/test/unit/output/adapter/csv_test.rb index 887e0407..db07d999 100644 --- a/test/unit/output/adapter/csv_test.rb +++ b/test/unit/output/adapter/csv_test.rb @@ -59,14 +59,14 @@ }]} it "should ommit column of type Id by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.wont_match(/.*Id.*/) out.wont_match(/.*2000,.*/) end it "should print column of type Id when --show-ids is set" do adapter = HammerCLI::Output::Adapter::CSValues.new( { :show_ids => true } ) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*Id.*/) end end @@ -75,12 +75,12 @@ let(:empty_data) { HammerCLI::Output::RecordCollection.new [] } it "should print headers by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*Name.*/) end it "should print headers by default even if there is no data" do - out, err = capture_io { adapter.print_collection(fields, empty_data) } + out, _ = capture_io { adapter.print_collection(fields, empty_data) } out.must_match(/.*Name.*/) end @@ -202,7 +202,7 @@ def format(data, field_params={}) end adapter = HammerCLI::Output::Adapter::CSValues.new({}, { :Field => [ DotFormatter.new ]}) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*-DOT-.*/) end @@ -215,7 +215,7 @@ def format(data, field_params={}) adapter = HammerCLI::Output::Adapter::CSValues.new({}, { :Field => [ NilFormatter.new ]}) nil_data = HammerCLI::Output::RecordCollection.new [{ :name => nil }] - out, err = capture_io { adapter.print_collection([field_name], nil_data) } + out, _ = capture_io { adapter.print_collection([field_name], nil_data) } out.must_match(/.*NIL.*/) end end diff --git a/test/unit/output/adapter/table_test.rb b/test/unit/output/adapter/table_test.rb index 85313165..260d2263 100644 --- a/test/unit/output/adapter/table_test.rb +++ b/test/unit/output/adapter/table_test.rb @@ -94,7 +94,7 @@ } it "should ommit column of type Id by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.wont_match(/.*ID.*/) end @@ -110,7 +110,7 @@ it "should print column of type Id when --show-ids is set" do adapter = HammerCLI::Output::Adapter::Table.new( { :show_ids => true } ) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*ID.*/) end @@ -128,12 +128,12 @@ context "handle headers" do it "should print headers by default" do - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*NAME.*/) end it "should print headers by default even if there is no data" do - out, err = capture_io { adapter.print_collection(fields, empty_data) } + out, _ = capture_io { adapter.print_collection(fields, empty_data) } out.must_match(/.*NAME.*/) end @@ -353,7 +353,7 @@ def format(data, field_params={}) end adapter = HammerCLI::Output::Adapter::Table.new({}, { :Field => [ DotFormatter.new ]}) - out, err = capture_io { adapter.print_collection(fields, data) } + out, _ = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*-DOT-.*/) end