Module: SimpleScripting::Argv
Defined Under Namespace
Classes: ArgumentError, ExitWithArgumentsHelpPrinting, ExitWithCommandsHelpPrinting, InvalidCommand
Instance Method Summary collapse
Instance Method Details
#decode(*definition_and_options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/simple_scripting/argv.rb', line 40 def decode(*) params_definition, = () arguments = .fetch(:arguments, ARGV) long_help = [:long_help] auto_help = .fetch(:auto_help, true) output = .fetch(:output, $stdout) raise_errors = .fetch(:raise_errors, false) # WATCH OUT! @long_help can also be set in :decode_command!. See issue #17. # @long_help = long_help exit_data = catch(:exit) do if params_definition.first.is_a?(Hash) return decode_command!(params_definition, arguments, auto_help) else return decode_arguments!(params_definition, arguments, auto_help) end end exit_data.print_help(output, @long_help) nil # to be used with the 'decode(...) || exit' pattern rescue SimpleScripting::Argv::ArgumentError, SimpleScripting::Argv::InvalidCommand, OptionParser::InvalidOption => error if raise_errors raise else output.puts "Command error!: #{error.}" end ensure @long_help = nil end |