Sha256: 537bdb964f7c01a2d3cc48f81191110832ddeaf7928749ed2d3149cb2fcec651
Contents?: true
Size: 1.19 KB
Versions: 13
Compression:
Stored size: 1.19 KB
Contents
# encoding: utf-8 module Nake module ArgvParser def self.extract!(args) args.dup.inject(Hash.new) do |options, argument| key, value = self.parse(argument) if key options[key] = value args.delete(argument) end options end end def self.extract(args) args.inject(Hash.new) do |options, argument| key, value = self.parse(argument) if key options[key] = value end options end end def self.parse!(argument) self.parse(argument) || raise("Argument #{argument} can't be parsed!") end def self.parse(argument) case argument when /^--no-([^=]+)$/ # --no-git-repository return [$1.gsub("-", "_").to_sym, false] when /^--([^=]+)$/ # --git-repository return [$1.gsub("-", "_").to_sym, true] when /^--([^=]+)=([^,]+)$/ # --controller=post key, value = $1, $2 return [key.gsub("-", "_").to_sym, value.dup] when /^--([^=]+)=(.+)$/ # --controllers=posts,comments key, value = $1, $2 return [key.gsub("-", "_").to_sym, value.split(",")] else return false end end end end
Version data entries
13 entries across 13 versions & 2 rubygems