Method: CommandMapper::Command.option
- Defined in:
- lib/command_mapper/command.rb
.option(flag, name: nil, value: nil, repeats: false, equals: nil, value_in_flag: nil, &block) ⇒ Object
Defines an option for the command.
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/command_mapper/command.rb', line 413 def self.option(flag, name: nil, value: nil, repeats: false, # formatting options equals: nil, value_in_flag: nil, &block) option = Option.new(flag, name: name, value: value, repeats: repeats, # formatting options equals: equals, value_in_flag: value_in_flag, &block) if is_internal_method?(option.name) if name raise(ArgumentError,"option #{flag.inspect} with name #{name.inspect} cannot override the internal method with same name: ##{option.name}") else raise(ArgumentError,"option #{flag.inspect} maps to method name ##{option.name} and cannot override the internal method with same name: ##{option.name}") end elsif has_argument?(option.name) raise(ArgumentError,"option #{flag.inspect} with name #{option.name.inspect} conflicts with another argument with the same name") elsif has_subcommand?(option.name) raise(ArgumentError,"option #{flag.inspect} with name #{option.name.inspect} conflicts with another subcommand with the same name") end self.[option.name] = option attr_accessor option.name end |