Object
New Option.
def initialize(name, parent=nil, &block)
# File lib/clio/usage/option.rb, line 38 def initialize(name, &block) @name = clean_name(name) #@parent = parent @aliases = [] @arguments = [] @multiple = false #@greedy = false @exclude = [] @help = '' instance_eval(&block) if block end
# File lib/clio/usage/option.rb, line 171 def ===(other) other = clean_key(other) return true if clean_key(key) == other return true if aliases.include?(other) return false end
Argument shorthand.
arg('PIN', 'pin number')
# File lib/clio/usage/option.rb, line 137 def arg(slot, help=nil) argument(slot).help(help) end
Assign an argument to the option.
# File lib/clio/usage/option.rb, line 87 def argument(name, &block) arg = Argument.new(name) #, self) arg.instance_eval(&block) if block @arguments << arg arg end
Tab completion.
# File lib/clio/usage/option.rb, line 126 def completion arguments.collect{|c| c.type} end
Is this option a boolean flag?
# File lib/clio/usage/option.rb, line 84 def flag?; @arguments.empty?; end
# File lib/clio/usage/option.rb, line 51 def initialize_copy(o) @name = o.name.dup @aliases = o.aliases.dup #@multiple = o.multiple @exclude = o.exclude.dup @help = o.help.dup end
# File lib/clio/usage/option.rb, line 72 def inspect to_s #s = "[--#{key}" #s << "*" if multiple #s << "=" + arguments.join(',') unless arguments.empty? #s << " " + aliases.collect{ |a| "-#{a}" } unless aliases.empty? ##s << " @excludes=#{@excludes.inspect}" unless @excludes.empty? #s << "]" #s end
Same as name but given as a symbol.
# File lib/clio/usage/option.rb, line 60 def key name.to_sym end
Can this option occur multiple times in the command line?
# File lib/clio/usage/option.rb, line 66 def multiple? ; @multiple ; end
# File lib/clio/usage/option.rb, line 142 def to_s tiny = aliases.select do |a| a.to_s.size == 1 end tiny.unshift(name) if name.size == 1 long = aliases.select do |a| a.to_s.size > 1 end long.unshift(name) if name.size > 1 tiny = tiny.collect{ |l| "-#{l}" } long = long.collect{ |w| "--#{w}" } if tiny.empty? opts = [ ' ', *long ] else opts = tiny + long end unless arguments.empty? args = arguments.collect{ |a| a.to_s.sub(/^[<]/,'').sub(/[>]$/,'') } opts.last << "=" + args.join(',') end opts.join(' ') end
Generated with the Darkfish Rdoc Generator 2.