Skip to content

Commit

Permalink
Nicer output when param value omitted
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshire137 committed Nov 26, 2024
1 parent 8a03294 commit 5c83058
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/project_pull_mover/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
10 changes: 10 additions & 0 deletions test/lib/project_pull_mover/options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 5c83058

Please sign in to comment.