class Erubis::Main
def parse_argv(argv, arg_none='', arg_required='', arg_optional='')
def parse_argv(argv, arg_none='', arg_required='', arg_optional='') options = {} context = {} while argv[0] && argv[0][0] == ?- optstr = argv.shift optstr = optstr[1, optstr.length-1] # if optstr[0] == ?- # context optstr =~ /\A\-([-\w]+)(?:=(.*))?/ or raise CommandOptionError.new("-#{optstr}: invalid context value.") name, value = $1, $2 name = name.gsub(/-/, '_').intern #value = value.nil? ? true : YAML.load(value) # error, why? value = value.nil? ? true : YAML.load("---\n#{value}\n") context[name] = value # else # options while optstr && !optstr.empty? optchar = optstr[0].chr optstr = optstr[1..-1] if arg_none.include?(optchar) options[optchar] = true elsif arg_required.include?(optchar) arg = optstr.empty? ? argv.shift : optstr or raise CommandOptionError.new("-#{optchar}: #{@option_names[optchar]} required.") options[optchar] = arg optstr = nil elsif arg_optional.include?(optchar) arg = optstr.empty? ? true : optstr options[optchar] = arg optstr = nil else raise CommandOptionError.new("-#{optchar}: unknown option.") end end end # end # end of while return options, context end