Class: Cl::Args
Instance Method Summary collapse
- #apply(cmd, args, opts) ⇒ Object
- #args ⇒ Object
- #define(const, name, *args) ⇒ Object
- #each(&block) ⇒ Object
- #index(*args, &block) ⇒ Object
Instance Method Details
#apply(cmd, args, opts) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/cl/args.rb', line 16 def apply(cmd, args, opts) return args if self.args.empty? || opts[:help] args = grouped(args) validate(args) args.map { |(arg, value)| arg.set(cmd, value) }.flatten(1) end |
#args ⇒ Object
31 32 33 |
# File 'lib/cl/args.rb', line 31 def args @args ||= [] end |
#define(const, name, *args) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/cl/args.rb', line 7 def define(const, name, *args) opts = args.last.is_a?(Hash) ? args.pop.dup : {} opts[:description] = args.shift if args.any? arg = Arg.new(name, opts) arg.define(const) self.args << arg end |
#each(&block) ⇒ Object
23 24 25 |
# File 'lib/cl/args.rb', line 23 def each(&block) args.each(&block) end |
#index(*args, &block) ⇒ Object
27 28 29 |
# File 'lib/cl/args.rb', line 27 def index(*args, &block) self.args.index(*args, &block) end |