Class: Cl::Args

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cl/args.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject



35
36
37
# File 'lib/cl/args.rb', line 35

def args
  @args ||= []
end

Instance Method Details

#apply(cmd, values, opts) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/cl/args.rb', line 16

def apply(cmd, values, opts)
  values = splat(values) if splat?
  values = default(values) if default?
  validate(values)
  return values if args.empty?
  values = args.zip(values).map { |(arg, value)| arg.set(cmd, value) }.flatten(1) #.compact
  compact_args(values)
end

#clearObject



39
40
41
# File 'lib/cl/args.rb', line 39

def clear
  args.clear
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

#dupObject



43
44
45
46
47
# File 'lib/cl/args.rb', line 43

def dup
  args = super
  args.args = args.args.dup
  args
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/cl/args.rb', line 25

def each(&block)
  args.each(&block)
end

#index(*args, &block) ⇒ Object



29
30
31
# File 'lib/cl/args.rb', line 29

def index(*args, &block)
  self.args.index(*args, &block)
end