Skip to content

Commit

Permalink
reverted to consistent argument errors for opt cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Oct 11, 2009
1 parent 52f8d17 commit 71e602a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/boson/runners/bin_runner.rb
Expand Up @@ -79,7 +79,7 @@ def execute_command
@args = @args.join(" ") if ((com = Boson::Command.find(@command)) && com.option_command?)
render_output dispatcher.send(subcommand || command, *@args)
rescue ArgumentError
puts "Wrong number of arguments for #{@command}\n\n"
puts "'#{@command}' was called incorrectly."
print_command_help
end

Expand Down
10 changes: 3 additions & 7 deletions lib/boson/scientist.rb
Expand Up @@ -129,13 +129,9 @@ def translate_args(obj, command, args)
return @args if @no_option_commands.include?(@command)
@args << parsed_options
if @args.size != command.arg_size && !command.has_splat_args?
command_size = @args.size > command.arg_size ? command.arg_size : command.arg_size - 1
if @args.size - 1 == command_size
raise Error, "Arguments are misaligned. Possible causes are incorrect argument "+
"size or no argument for this method's options."
else
raise ArgumentError, "wrong number of arguments (#{@args.size - 1} for #{command_size})"
end
command_size, args_size = @args.size > command.arg_size ? [command.arg_size, @args.size] :
[command.arg_size - 1, @args.size - 1]
raise ArgumentError, "wrong number of arguments (#{args_size} for #{command_size})"
end
end
@args
Expand Down
2 changes: 1 addition & 1 deletion test/bin_runner_test.rb
Expand Up @@ -59,7 +59,7 @@ def start(*args)
end

test "command and too many arguments prints error" do
capture_stdout { start('commands','1','2','3') }.should =~ /Wrong number/
capture_stdout { start('commands','1','2','3') }.should =~ /'commands'.*incorrect/
end

test "failed subcommand prints error and not command not found" do
Expand Down
13 changes: 7 additions & 6 deletions test/scientist_test.rb
Expand Up @@ -136,7 +136,7 @@ def args_are_equal(args, array)
end

test "with no argument defined for options" do
capture_stderr { command({:args=>1}, 'ok') }.should =~ /misaligned/
assert_error(ArgumentError, '2 for 1') { command({:args=>1}, 'ok') }
end
end

Expand Down Expand Up @@ -173,11 +173,12 @@ def args_are_equal(args, array)
end

test "with too many args raises ArgumentError" do
args = [ArgumentError, '3 for 2']
assert_error(*args) { command_with_args 1,2,3 }
assert_error(*args) { command_with_args '1 2 3' }
assert_error(*args) { command_with_arg_size 1,2,3 }
assert_error(*args) { command_with_arg_size '1 2 3' }
args3 = [ArgumentError, '3 for 2']
args4 = [ArgumentError, '4 for 2']
assert_error(*args3) { command_with_args 1,2,3 }
assert_error(*args4) { command_with_args '1 2 3' }
assert_error(*args3) { command_with_arg_size 1,2,3 }
assert_error(*args4) { command_with_arg_size '1 2 3' }
end
end

Expand Down

0 comments on commit 71e602a

Please sign in to comment.