Class: Cmdopt::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdopt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



123
124
125
# File 'lib/cmdopt.rb', line 123

def initialize
  @schema = Schema.new
end

Instance Attribute Details

#schemaObject

Returns the value of attribute schema.



127
128
129
# File 'lib/cmdopt.rb', line 127

def schema
  @schema
end

Instance Method Details

#help(width = nil, indent = " ") ⇒ Object



134
135
136
# File 'lib/cmdopt.rb', line 134

def help(width=nil, indent="  ")
  return @schema.help(width, indent)
end

#option(options, desc) ⇒ Object



129
130
131
132
# File 'lib/cmdopt.rb', line 129

def option(options, desc)
  item = @schema.add(options, desc)
  return Builder.new(item)
end

#parse(args, defaults = nil) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/cmdopt.rb', line 138

def parse(args, defaults=nil)
  opts = _new_opts(defaults)
  while ! args.empty?
    arg = args.shift
    case arg
    when "--" ;  break
    when /^--/;  _parse_long(arg, opts)
    when /^-/ ;  _parse_short(arg, args, opts)
    else
      args.unshift(arg)
      break
    end
  end
  return opts
end