Class: Clio::Usage::Parser
- Inherits:
-
Object
- Object
- Clio::Usage::Parser
- Defined in:
- lib/clio/usage/parser.rb
Overview
Parser
Parse commandline arguments according to given Usage.
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#signatures ⇒ Object
readonly
Returns the value of attribute signatures.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #errors ⇒ Object (also: #parse_errors)
-
#initialize(usage, argv) ⇒ Parser
constructor
, index=0).
- #inspect ⇒ Object
- #key ⇒ Object
- #name ⇒ Object
- #parse ⇒ Object
-
#parsed? ⇒ Boolean
Has the commandline been parsed?.
Constructor Details
#initialize(usage, argv) ⇒ Parser
, index=0)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/clio/usage/parser.rb', line 20 def initialize(usage, argv) #, index=0) # convert to array if argv string if ::String===argv argv = Shellwords.shellwords(argv) else argv = argv.dup end @usage = usage @argv = argv @parsed = false @signatures = [] @errors = [] end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
15 16 17 |
# File 'lib/clio/usage/parser.rb', line 15 def argv @argv end |
#signatures ⇒ Object (readonly)
Returns the value of attribute signatures.
17 18 19 |
# File 'lib/clio/usage/parser.rb', line 17 def signatures @signatures end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
14 15 16 |
# File 'lib/clio/usage/parser.rb', line 14 def usage @usage end |
Instance Method Details
#errors ⇒ Object Also known as: parse_errors
175 176 177 |
# File 'lib/clio/usage/parser.rb', line 175 def errors @errors end |
#inspect ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/clio/usage/parser.rb', line 41 def inspect s = "<" + signatures.inspect + ">" s #s = "#<#{self.class}" #s << " @options=#{@options.inspect}" unless @options.empty? #s << " @arguments=#{@arguments.inspect}" unless @arguments.empty? #s << " @subcommand=#{@subcommand}>" if @subcommand #s << ">" #s end |
#key ⇒ Object
38 |
# File 'lib/clio/usage/parser.rb', line 38 def key ; usage.key ; end |
#name ⇒ Object
37 |
# File 'lib/clio/usage/parser.rb', line 37 def name ; usage.name ; end |
#parse ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/clio/usage/parser.rb', line 53 def parse @parsed = false @signatures = [] @errors = [] parse_command(usage, argv.dup) @parsed = true return Interface.new(@signatures, @errors) end |
#parsed? ⇒ Boolean
Has the commandline been parsed?
66 |
# File 'lib/clio/usage/parser.rb', line 66 def parsed? ; @parsed ; end |