diff --git a/lib/project_pull_mover/options.rb b/lib/project_pull_mover/options.rb index 4947293..a8f77e9 100644 --- a/lib/project_pull_mover/options.rb +++ b/lib/project_pull_mover/options.rb @@ -89,6 +89,10 @@ def parse @option_parser.parse!(@argv, into: @options) return true if print_version? valid? + rescue OptionParser::MissingArgument => err + log_error("Error: #{err.message}") + @logger.info(to_s) + false end sig { returns(T::Boolean) } diff --git a/test/lib/project_pull_mover/options_test.rb b/test/lib/project_pull_mover/options_test.rb index 5dde857..ba0cec2 100644 --- a/test/lib/project_pull_mover/options_test.rb +++ b/test/lib/project_pull_mover/options_test.rb @@ -39,6 +39,16 @@ module ProjectPullMover assert_match(/Error: invalid project owner type/, @err_stream.string) end + it "raises exception when argument requiring a value is not given one" do + error = assert_raises(Options::InvalidOptionsError) do + Options.parse(file: "ScriptFileName", logger: @logger, argv: ["-p"]) + end + + assert_equal "Error: missing argument: -p", error.message + assert_match(/Usage: ScriptFileName /, @out_stream.string) + assert_match(/Error: missing argument: -p/, @err_stream.string) + end + it "does not raise for missing required parameters when version flag is passed" do options = Options.parse(file: "project_pull_mover.rb", logger: @logger, argv: ["-v"]) assert_predicate options, :print_version?