class Eco::CLI::Scripting::Arguments
Attributes
args[R]
Public Class Methods
new(args = ARGV)
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 9 def initialize(args = ARGV) @args = args @known = {} end
Public Instance Methods
<<(arg)
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 23 def <<(arg) raise "Expected Argument. Given #{arg.class}" unless arg.is_a?(Argument) if karg = @known[arg.key] #puts "Found already existent option #{arg.key} (with_param: arg.with_param?)" karg.with_param! if arg.with_param? else #puts "Adding unexistent option #{arg.key}" @known[arg.key] = arg end self end
add(key, with_param: false)
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 19 def add(key, with_param: false) self << Argument.new(key, with_param: with_param) end
any_unkown?(exclude: [])
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 49 def any_unkown?(exclude: []) unknown(exclude: exclude).length > 0 end
each(&block)
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 14 def each(&block) return to_enum(:each) unless block @known.values.each(&block) end
keys()
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 39 def keys @known.keys end
known?(value)
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 35 def known?(value) @known.key?(to_key(value)) end
unknown(exclude: [])
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 43 def unknown(exclude: []) reduce(args.dup - exclude) do |not_known, arg| arg.args_slice(*not_known) end end
Private Instance Methods
to_key(value)
click to toggle source
# File lib/eco/cli/scripting/arguments.rb, line 55 def to_key(value) case value when String value when Argument value.key else "Missuse: only able to transform to key a String or an Argument. Given #{value.class}" end end