remove backtrace from stderr for unknown CLI options - close #69

This commit is contained in:
josh committed 2018-11-30 23:29:19 -05:00
1 parent 6180410cc4
commit ba69f05e99
2 files changed
+30 -2

No files matched your search

+12 -2
View File
@@ -43,6 +43,18 @@ module Rscons
# @return [void] # @return [void]
def run(argv) def run(argv)
argv = argv.dup argv = argv.dup
begin
exit run_toplevel(argv)
rescue OptionParser::InvalidOption => io
$stderr.puts io.message
$stderr.puts USAGE
exit 2
end
end
private
def run_toplevel(argv)
rsconscript = nil rsconscript = nil
do_help = false do_help = false
@@ -115,8 +127,6 @@ module Rscons
exit Rscons.application.run(operation, script, operation_options) exit Rscons.application.run(operation, script, operation_options)
end end
private
def parse_operation_args(operation, argv) def parse_operation_args(operation, argv)
case operation case operation
when "configure" when "configure"
+18
View File
@@ -1531,6 +1531,24 @@ EOF
expect(result.stderr).to match /Unknown operation: unknownop/ expect(result.stderr).to match /Unknown operation: unknownop/
expect(result.status).to_not eq 0 expect(result.status).to_not eq 0
end end
it "displays usage and error message without a backtrace for an invalid CLI option" do
test_dir "simple"
result = run_rscons(rscons_args: %w[--xyz])
expect(result.stderr).to_not match /Traceback/
expect(result.stderr).to match /invalid option.*--xyz/
expect(result.stderr).to match /Usage:/
expect(result.status).to_not eq 0
end
it "displays usage and error message without a backtrace for an invalid CLI option to a valid subcommand" do
test_dir "simple"
result = run_rscons(op: %w[configure --xyz])
expect(result.stderr).to_not match /Traceback/
expect(result.stderr).to match /invalid option.*--xyz/
expect(result.stderr).to match /Usage:/
expect(result.status).to_not eq 0
end
end end
context "configure" do context "configure" do