lib/cri/command_dsl.rb in cri-2.11.0 vs lib/cri/command_dsl.rb in cri-2.12.0

- old
+ new

@@ -126,36 +126,29 @@ # @option params [Boolean] :hidden Whether or not the option should # be printed in the help output # # @return [void] def option(short, long, desc, params = {}, &block) - requiredness = params.fetch(:argument, :forbidden) - multiple = params.fetch(:multiple, false) - hidden = params.fetch(:hidden, false) - default = params.fetch(:default, nil) - transform = params.fetch(:transform, nil) - - if short.nil? && long.nil? - raise ArgumentError, 'short and long options cannot both be nil' - end - - if default && requiredness == :forbidden - raise ArgumentError, 'a default value cannot be specified for flag options' - end - - @command.option_definitions << { - short: short.nil? ? nil : short.to_s, - long: long.nil? ? nil : long.to_s, - desc: desc, - argument: requiredness, - multiple: multiple, - block: block, - hidden: hidden, - default: default, - transform: transform, - } + @command.option_definitions << Cri::OptionDefinition.new( + short: short&.to_s, + long: long&.to_s, + desc: desc, + argument: params.fetch(:argument, :forbidden), + multiple: params.fetch(:multiple, false), + block: block, + hidden: params.fetch(:hidden, false), + default: params.fetch(:default, nil), + transform: params.fetch(:transform, nil), + ) end alias opt option + + # Defines a new parameter for the command. + # + # @param [Symbol] name The name of the parameter + def param(name) + @command.parameter_definitions << Cri::ParamDefinition.new(name: name) + end # 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, nil] short The short option name