Method: CommandMapper::Command#command_argv
- Defined in:
- lib/command_mapper/command.rb
#command_argv ⇒ Array<String>
Returns an Array of command-line arguments for the command.
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/command_mapper/command.rb', line 673 def command_argv argv = [@command_path || @command_name] self.class..each do |name,option| unless (value = self[name]).nil? option.argv(argv,value) end end if @command_subcommand # a subcommand takes precedence over any command arguments argv.concat(@command_subcommand.command_argv) else additional_args = [] self.class.arguments.each do |name,argument| value = self[name] if value.nil? if argument.required? raise(ArgumentRequired,"argument #{name} is required") end else argument.argv(additional_args,value) end end if additional_args.any? { |arg| arg.start_with?('-') } # append a '--' separator if any of the arguments start with a '-' argv << '--' end argv.concat(additional_args) end return argv end |