Class: Cmdopt::Parser
- Inherits:
-
Object
- Object
- Cmdopt::Parser
- Defined in:
- lib/cmdopt.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
- #help(width = nil, indent = " ") ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #option(options, desc) ⇒ Object
- #parse(args, defaults = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#schema ⇒ Object
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(, desc) item = @schema.add(, 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 |