diff --git a/bin/appliance_console b/bin/appliance_console index d665edab..8e2169df 100755 --- a/bin/appliance_console +++ b/bin/appliance_console @@ -8,19 +8,19 @@ Bundler.setup require 'manageiq-appliance_console' require 'fileutils' +# defines globally /via kernal: agree(), ask(), choose() and say() require 'highline/import' -require 'highline/system_extensions' require 'rubygems' require 'bcrypt' require 'linux_admin' -require 'manageiq/appliance_console/postgres_admin' require 'awesome_spawn' -include HighLine::SystemExtensions require 'manageiq/appliance_console/i18n' -$terminal.wrap_at = 80 -$terminal.page_at = 35 +HighLine.default_instance.tap do |highline| + highline.wrap_at = 80 + highline.page_at = 35 +end def summary_entry(field, value) dfield = "#{field}:" @@ -141,7 +141,7 @@ Welcome to the #{I18n.t("product.name")} Virtual Appliance. To modify the configuration, use a web browser to access the management page. -#{$terminal.list(summary_attributes)} +#{HighLine.default_instance.list(summary_attributes)} EOL press_any_key diff --git a/lib/manageiq-appliance_console.rb b/lib/manageiq-appliance_console.rb index d6b2b085..455e0988 100644 --- a/lib/manageiq-appliance_console.rb +++ b/lib/manageiq-appliance_console.rb @@ -43,6 +43,7 @@ def self.logger require 'manageiq/appliance_console/message_configuration_server' require 'manageiq/appliance_console/oidc_authentication' require 'manageiq/appliance_console/principal' +require 'manageiq/appliance_console/postgres_admin' require 'manageiq/appliance_console/saml_authentication' require 'manageiq/appliance_console/scap' require 'manageiq/appliance_console/temp_storage_configuration' diff --git a/lib/manageiq/appliance_console/prompts.rb b/lib/manageiq/appliance_console/prompts.rb index 6da629cc..f9363195 100644 --- a/lib/manageiq/appliance_console/prompts.rb +++ b/lib/manageiq/appliance_console/prompts.rb @@ -34,7 +34,11 @@ def ask_for_uri(prompt, expected_scheme, opts = {}) def press_any_key say("\nPress any key to continue.") - STDIN.noecho(&:getch) + HighLine.default_instance.tap do |highline| + highline.terminal.raw_no_echo_mode_exec do + highline.terminal.get_character + end + end end def clear_screen diff --git a/manageiq-appliance_console.gemspec b/manageiq-appliance_console.gemspec index d41f811e..9515509a 100644 --- a/manageiq-appliance_console.gemspec +++ b/manageiq-appliance_console.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "awesome_spawn", "~> 1.4" spec.add_runtime_dependency "bcrypt", "~> 3.1.10" spec.add_runtime_dependency "bcrypt_pbkdf", ">= 1.0", "< 2.0" - spec.add_runtime_dependency "highline", "~> 1.6.21" + spec.add_runtime_dependency "highline", "~> 2.1" spec.add_runtime_dependency "i18n", ">= 0.8" spec.add_runtime_dependency "linux_admin", "~> 2.0" spec.add_runtime_dependency "manageiq-password", "< 2" diff --git a/spec/database_admin_spec.rb b/spec/database_admin_spec.rb index 8e2f5f53..3f2a03ac 100644 --- a/spec/database_admin_spec.rb +++ b/spec/database_admin_spec.rb @@ -98,7 +98,7 @@ expect(subject.ask_file_location).to be_truthy error = "Please provide #{errmsg}" - expect_heard ["Enter the #{prmpt}: ", error, prompt] + expect_heard ["Enter the #{prmpt}: |/tmp/evm_db.backup| ", error, prompt] expect(subject.database_opts[:local_file]).to eq(file.path) end @@ -555,22 +555,17 @@ def confirm_and_execute context "when excluding tables" do it "asks to input tables, providing an example and sensible defaults" do - pending "something is wrong with this test and the readline mocking on CI" if ENV["CI"] - say ["y", "metrics_*"] expect(subject.ask_for_tables_to_exclude_in_dump).to be_truthy - expect_output <<-EXAMPLE.strip_heredoc - + expect_output <<-EXAMPLE.strip_heredoc.chomp + Would you like to exclude tables in the dump? (Y/N): To exclude tables from the dump, enter them in a space separated list. For example: > metrics_* vim_performance_states event_streams + Enter the tables to exclude: |metrics_* vim_performance_states event_streams| EXAMPLE - expect_readline_question_asked <<-PROMPT.strip_heredoc.chomp - Would you like to exclude tables in the dump? (Y/N): y - Enter the tables to exclude: |metrics_* vim_performance_states event_streams| - PROMPT end it "adds `:exclude_table_data => ['metrics_*', 'vms']` to @database_opts" do diff --git a/spec/prompts_spec.rb b/spec/prompts_spec.rb index 77438726..1e5cb0b4 100644 --- a/spec/prompts_spec.rb +++ b/spec/prompts_spec.rb @@ -277,7 +277,8 @@ expect(subject.ask_for_disk("database disk").path).to eq("/dev/a") expect_heard ["database disk", "", "", "1) /dev/a: 10 MB", "", - "2) Don't partition the disk", "", "", + "2) Don't partition the disk", "", + "(1) ", "", "Choose the database disk: |1| "] end end @@ -328,28 +329,28 @@ say "" expect_cls expect(subject.ask_with_menu("q?", %w(a b), 1)).to eq("a") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |1| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(1) ", "", "Choose the q?: |1| "] end it "defaults to the number of a menu option" do say "" expect_cls expect(subject.ask_with_menu("q?", {"a" => "a1", "b" => "b1"}, 1)).to eq("a1") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |1| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(1) ", "", "Choose the q?: |1| "] end it "defaults to the index of a menu hash key option" do say "" expect_cls expect(subject.ask_with_menu("q?", {"a" => "a1", "b" => "b1"}, "a")).to eq("a1") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |1| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(1) ", "", "Choose the q?: |1| "] end it "defaults to the index of a menu hash value option" do say "" expect_cls expect(subject.ask_with_menu("q?", {"a" => "a1", "b" => "b1"}, "b1")).to eq("b1") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |2| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(2) ", "", "Choose the q?: |2| "] end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f87f0859..5097bdce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,18 +3,6 @@ SimpleCov.start end -# In GitHub Actions (CI), we do not have a tty, so the various tests that use -# STDIN in order to test interactivity will fail. This code creates a psuedo-tty -# in that environment. If you want to test locally in a "non-tty" way, you can -# run the tests as follows: `true | bundle exec rake 2>&1 | cat` -unless STDIN.tty? - require "pty" - require "io/console" - _master_io, slave_file = PTY.open - slave_file.raw! - STDIN.reopen(slave_file) -end - require "manageiq-appliance_console" ManageIQ::ApplianceConsole.logger = Logger.new("/dev/null") diff --git a/spec/support/ui.rb b/spec/support/ui.rb index 3b4e105b..cf99908a 100644 --- a/spec/support/ui.rb +++ b/spec/support/ui.rb @@ -11,6 +11,7 @@ File.open(@temp_stdin.path, 'w+') end + # this is now data typed in our tests by us via 'say' let(:readline_output) do @temp_stdout = Tempfile.new("temp_stdout") File.open(@temp_stdout.path, 'w+') @@ -56,14 +57,6 @@ def expect_cls expect(subject).to receive(:print) end - def expect_readline_question_asked(question) - readline_output.rewind - readline_output_content = readline_output.read - unless readline_output_content.empty? - expect(readline_output_content).to include(question) - end - end - def expect_output(strs) strs = strs.collect { |s| s == "" ? "\n" : s }.join if strs.kind_of?(Array) expect(output.string).to eq(strs) @@ -71,7 +64,6 @@ def expect_output(strs) def expect_heard(strs, check_eof = true) strs = Array(strs) - expect_readline_question_asked(strs.shift) unless readline_output.tap(&:rewind).read.empty? expect_output(strs) expect { subject.ask("is there more") }.to raise_error(EOFError) if check_eof expect(input).to be_eof