Class: CouchShell::Commandline::Opt
- Inherits:
-
Object
- Object
- CouchShell::Commandline::Opt
- Defined in:
- lib/couch-shell/commandline.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#long ⇒ Object
Returns the value of attribute long.
-
#short ⇒ Object
Returns the value of attribute short.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize ⇒ Opt
constructor
A new instance of Opt.
- #parse_spec!(optspec) ⇒ Object
Constructor Details
#initialize ⇒ Opt
Returns a new instance of Opt.
56 57 58 59 60 61 62 |
# File 'lib/couch-shell/commandline.rb', line 56 def initialize @short = nil @long = nil @value = nil @doc = nil @action = nil end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
54 55 56 |
# File 'lib/couch-shell/commandline.rb', line 54 def action @action end |
#doc ⇒ Object
Returns the value of attribute doc.
54 55 56 |
# File 'lib/couch-shell/commandline.rb', line 54 def doc @doc end |
#long ⇒ Object
Returns the value of attribute long.
54 55 56 |
# File 'lib/couch-shell/commandline.rb', line 54 def long @long end |
#short ⇒ Object
Returns the value of attribute short.
54 55 56 |
# File 'lib/couch-shell/commandline.rb', line 54 def short @short end |
#value ⇒ Object
Returns the value of attribute value.
54 55 56 |
# File 'lib/couch-shell/commandline.rb', line 54 def value @value end |
Instance Method Details
#parse_spec!(optspec) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/couch-shell/commandline.rb', line 64 def parse_spec!(optspec) value = nil case optspec when /\A--([^-= ][^= ]+)(=[^= ]+)?\z/ raise "long option already set" if @long @long = $1 value = ($2 ? $2[1..-1] : nil) when /\A-([^- ])( [^= ]+)?\z/ raise "short option already set" if @short @short = $1 value = ($2 ? $2[1..-1] : nil) else raise "invalid optspec `#{optspec}'" end if value if @value && @value != value raise "option value name mismatch: `#{value}' != `#{@value}'" end @value = value end end |