lib/cri/command_dsl.rb in cri-2.3.0 vs lib/cri/command_dsl.rb in cri-2.4.0

- old
+ new

@@ -90,13 +90,13 @@ end # Adds a new option to the command. If a block is given, it will be # executed when the option is successfully parsed. # - # @param [String, Symbol] short The short option name + # @param [String, Symbol, nil] short The short option name # - # @param [String, Symbol] long The long option name + # @param [String, Symbol, nil] long The long option name # # @param [String] desc The option description # # @option params [:forbidden, :required, :optional] :argument Whether the # argument is forbidden, required or optional @@ -109,13 +109,13 @@ alias_method :opt, :option # Adds a new option with a required argument to the command. If a block is # given, it will be executed when the option is successfully parsed. # - # @param [String, Symbol] short The short option name + # @param [String, Symbol, nil] short The short option name # - # @param [String, Symbol] long The long option name + # @param [String, Symbol, nil] long The long option name # # @param [String] desc The option description # # @return [void] # @@ -125,13 +125,13 @@ end # Adds a new option with a forbidden argument to the command. If a block # is given, it will be executed when the option is successfully parsed. # - # @param [String, Symbol] short The short option name + # @param [String, Symbol, nil] short The short option name # - # @param [String, Symbol] long The long option name + # @param [String, Symbol, nil] long The long option name # # @param [String] desc The option description # # @return [void] # @@ -142,13 +142,13 @@ alias_method :forbidden, :flag # Adds a new option with an optional argument to the command. If a block # is given, it will be executed when the option is successfully parsed. # - # @param [String, Symbol] short The short option name + # @param [String, Symbol, nil] short The short option name # - # @param [String, Symbol] long The long option name + # @param [String, Symbol, nil] long The long option name # # @param [String] desc The option description # # @return [void] # @@ -187,12 +187,16 @@ end protected def add_option(short, long, desc, argument, block) + if short.nil? && long.nil? + raise ArgumentError, "short and long options cannot both be nil" + end + @command.option_definitions << { - :short => short.to_s, - :long => long.to_s, + :short => short.nil? ? nil : short.to_s, + :long => long.nil? ? nil : long.to_s, :desc => desc, :argument => argument, :block => block } end