Class: CouchShell::Commandline::Opt

Inherits:
Object
  • Object
show all
Defined in:
lib/couch-shell/commandline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOpt

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

#actionObject

Returns the value of attribute action.



54
55
56
# File 'lib/couch-shell/commandline.rb', line 54

def action
  @action
end

#docObject

Returns the value of attribute doc.



54
55
56
# File 'lib/couch-shell/commandline.rb', line 54

def doc
  @doc
end

#longObject

Returns the value of attribute long.



54
55
56
# File 'lib/couch-shell/commandline.rb', line 54

def long
  @long
end

#shortObject

Returns the value of attribute short.



54
55
56
# File 'lib/couch-shell/commandline.rb', line 54

def short
  @short
end

#valueObject

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