Skip to content

Commit

Permalink
Change to inline errors and remove message arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Apr 15, 2020
1 parent f712ff0 commit a742dac
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
9 changes: 3 additions & 6 deletions lib/tty/option/parser/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def process_exact_arity(arg)

if 0 < values.size && values.size < arg.arity &&
Array(@defaults[arg.name]).size < arg.arity
error = InvalidArity.new(arg, values.size)
@error_aggregator.(error, error.message)
@error_aggregator.(InvalidArity.new(arg, values.size))
end

values
Expand Down Expand Up @@ -123,8 +122,7 @@ def process_infinite_arity(arg)
end

if values.size < arity && Array(@defaults[arg.name]).size < arity
error = InvalidArity.new(arg, values.size)
@error_aggregator.(error, error.message)
@error_aggregator.(InvalidArity.new(arg, values.size))
end

values
Expand Down Expand Up @@ -201,8 +199,7 @@ def check_required
return if @required.empty?

@required.each do |param|
error = MissingParameter.new(param)
@error_aggregator.(error, error.message)
@error_aggregator.(MissingParameter.new(param))
end
end
end # Arguments
Expand Down
6 changes: 2 additions & 4 deletions lib/tty/option/parser/environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def check_arity
min_arity = param.arity < 0 ? param.arity.abs - 1 : param.arity

if arity < min_arity
error = InvalidArity.new(param, arity)
@error_aggregator.(error, error.message)
@error_aggregator.(InvalidArity.new(param, arity))
end
end
end
Expand All @@ -195,8 +194,7 @@ def check_required
return if @required.empty?

@required.each do |param|
error = MissingParameter.new(param)
@error_aggregator.(error, error.message)
@error_aggregator.(MissingParameter.new(param))
end
end
end # Environments
Expand Down
6 changes: 2 additions & 4 deletions lib/tty/option/parser/keywords.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ def check_arity
min_arity = param.arity < 0 ? param.arity.abs - 1 : param.arity

if arity < min_arity
error = InvalidArity.new(param, arity)
@error_aggregator.(error, error.message)
@error_aggregator.(InvalidArity.new(param, arity))
end
end
end
Expand All @@ -180,8 +179,7 @@ def check_required
return if @required.empty?

@required.each do |param|
error = MissingParameter.new(param)
@error_aggregator.(error, error.message)
@error_aggregator.(MissingParameter.new(param))
end
end
end # Keywords
Expand Down
9 changes: 3 additions & 6 deletions lib/tty/option/parser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def process_double_option(long, sep, rest)
elsif !@argv.empty?
value = opt.multi_argument? ? consume_arguments : @argv.shift
else
error = MissingArgument.new(opt, long)
@error_aggregator.(error, error.message)
@error_aggregator.(MissingArgument.new(opt, long))
end
elsif opt.argument_optional?
if !rest.empty?
Expand Down Expand Up @@ -273,8 +272,7 @@ def check_arity
min_arity = param.arity < 0 ? param.arity.abs - 1 : param.arity

if arity < min_arity
error = InvalidArity.new(param, arity)
@error_aggregator.(error, error.message)
@error_aggregator.(InvalidArity.new(param, arity))
end
end
end
Expand All @@ -288,8 +286,7 @@ def check_required
return if @required.empty?

@required.each do |param|
error = MissingParameter.new(param)
@error_aggregator.(error, error.message)
@error_aggregator.(MissingParameter.new(param))
end
end
end # Options
Expand Down

0 comments on commit a742dac

Please sign in to comment.