Class: Clio::Usage::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/clio/usage/parser.rb

Overview

Parser

Parse commandline arguments according to given Usage.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argvObject (readonly)

Returns the value of attribute argv.



15
16
17
# File 'lib/clio/usage/parser.rb', line 15

def argv
  @argv
end

#signaturesObject (readonly)

Returns the value of attribute signatures.



17
18
19
# File 'lib/clio/usage/parser.rb', line 17

def signatures
  @signatures
end

#usageObject (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

#errorsObject Also known as: parse_errors



175
176
177
# File 'lib/clio/usage/parser.rb', line 175

def errors
  @errors
end

#inspectObject



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

#keyObject



38
# File 'lib/clio/usage/parser.rb', line 38

def key  ; usage.key  ; end

#nameObject



37
# File 'lib/clio/usage/parser.rb', line 37

def name ; usage.name ; end

#parseObject



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?

Returns:

  • (Boolean)


66
# File 'lib/clio/usage/parser.rb', line 66

def parsed? ; @parsed ; end