class Clio::Usage::Interface
Command Interface (toplevel signature)¶ ↑
The end result provide by Clio::Usage::Parser#parse. This class consists of an array of command signatures and parse errors.
Attributes
errors[R]
parse_errors[R]
signatures[R]
Public Class Methods
new(signatures=[], errors=[])
click to toggle source
# File lib/clio/usage/interface.rb, line 19 def initialize(signatures=[], errors=[]) @signatures = signatures @errors = errors end
Public Instance Methods
[](i)
click to toggle source
Index on each subcommand, with 0 being the toplevel command.
# File lib/clio/usage/interface.rb, line 88 def [](i) @signatures[i] end
arguments()
click to toggle source
# File lib/clio/usage/interface.rb, line 56 def arguments #parse unless parsed? @arguments ||= ( m = [] @signatures.each do |s| m.concat(s.arguments) end m ) end
command()
click to toggle source
TODO: Join by what character?
# File lib/clio/usage/interface.rb, line 25 def command return nil if commands.empty? return commands.join(' ') end
commands()
click to toggle source
# File lib/clio/usage/interface.rb, line 31 def commands #parse unless parsed? @commands ||= ( a = [] @signatures[1..-1].each do |s| a << s.command.to_s end a ) end
method_missing(s, *a)
click to toggle source
# File lib/clio/usage/interface.rb, line 99 def method_missing(s, *a) s = s.to_s case s #when /[=]$/ # n = s.chomp('=') # usage.option(n).type(*a) # #parser.parse # res = parser.options[n.to_sym] #when /[!]$/ # n = s.chomp('!') # res = parser.parse when /[?]$/ options[s.chomp('?').to_sym] else options[s.to_sym] end end
options()
click to toggle source
# File lib/clio/usage/interface.rb, line 43 def options #parse unless parsed? @options ||= ( h = {} @signatures.each do |s| h.merge!(s.options) end h ) end
Also aliased as: switches
parameters()
click to toggle source
Return parameters array of [*arguments, options]
# File lib/clio/usage/interface.rb, line 68 def parameters arguments + [options] end
to_a()
click to toggle source
# File lib/clio/usage/interface.rb, line 93 def to_a #parse unless parsed? @signatures.collect{ |s| s.to_a } end
valid?()
click to toggle source
Were the commandline arguments valid? This simply checks to see if there were any parse errors.
# File lib/clio/usage/interface.rb, line 82 def valid? #parse unless @parsed errors.empty? end