Class: Clio::Usage::Interface
- Inherits:
-
Object
- Object
- Clio::Usage::Interface
- Defined in:
- lib/clio/usage/interface.rb
Overview
Command Interface (toplevel signature)
The end result provide by Usage::Parser#parse. This class consists of an array of command signatures and parse errors.
Instance Attribute Summary collapse
-
#errors ⇒ Object
(also: #parse_errors)
readonly
Returns the value of attribute errors.
-
#signatures ⇒ Object
readonly
Returns the value of attribute signatures.
Instance Method Summary collapse
-
#[](i) ⇒ Object
Index on each subcommand, with 0 being the toplevel command.
- #arguments ⇒ Object
-
#command ⇒ Object
TODO: Join by what character?.
- #commands ⇒ Object
-
#initialize(signatures = [], errors = []) ⇒ Interface
constructor
A new instance of Interface.
- #method_missing(s, *a) ⇒ Object
- #options ⇒ Object (also: #switches)
-
#parameters ⇒ Object
Return parameters array of [*arguments, options].
- #to_a ⇒ Object
-
#valid? ⇒ Boolean
Were the commandline arguments valid? This simply checks to see if there were any parse errors.
Constructor Details
#initialize(signatures = [], errors = []) ⇒ Interface
Returns a new instance of Interface.
19 20 21 22 |
# File 'lib/clio/usage/interface.rb', line 19 def initialize(signatures=[], errors=[]) @signatures = signatures @errors = errors end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(s, *a) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# 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 /[?]$/ [s.chomp('?').to_sym] else [s.to_sym] end end |
Instance Attribute Details
#errors ⇒ Object (readonly) Also known as: parse_errors
Returns the value of attribute errors.
14 15 16 |
# File 'lib/clio/usage/interface.rb', line 14 def errors @errors end |
#signatures ⇒ Object (readonly)
Returns the value of attribute signatures.
13 14 15 |
# File 'lib/clio/usage/interface.rb', line 13 def signatures @signatures end |
Instance Method Details
#[](i) ⇒ Object
Index on each subcommand, with 0 being the toplevel command.
88 89 90 |
# File 'lib/clio/usage/interface.rb', line 88 def [](i) @signatures[i] end |
#arguments ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# 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 ⇒ Object
TODO: Join by what character?
25 26 27 28 |
# File 'lib/clio/usage/interface.rb', line 25 def command return nil if commands.empty? return commands.join(' ') end |
#commands ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# 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 |
#options ⇒ Object Also known as: switches
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/clio/usage/interface.rb', line 43 def #parse unless parsed? @options ||= ( h = {} @signatures.each do |s| h.merge!(s.) end h ) end |
#parameters ⇒ Object
Return parameters array of [*arguments, options]
68 69 70 |
# File 'lib/clio/usage/interface.rb', line 68 def parameters arguments + [] end |
#to_a ⇒ Object
93 94 95 96 |
# File 'lib/clio/usage/interface.rb', line 93 def to_a #parse unless parsed? @signatures.collect{ |s| s.to_a } end |
#valid? ⇒ Boolean
Were the commandline arguments valid? This simply checks to see if there were any parse errors.
82 83 84 85 |
# File 'lib/clio/usage/interface.rb', line 82 def valid? #parse unless @parsed errors.empty? end |