Class: DenCli::CMD::Opt
- Inherits:
-
Object
- Object
- DenCli::CMD::Opt
- Defined in:
- lib/dencli/cmd.rb
Instance Attribute Summary collapse
-
#conv ⇒ Object
readonly
Returns the value of attribute conv.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#long ⇒ Object
readonly
Returns the value of attribute long.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#req ⇒ Object
readonly
Returns the value of attribute req.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Instance Method Summary collapse
- #default ⇒ Object
- #default? ⇒ Boolean
-
#initialize(cmd, name, opt, *args, desc, default: NilClass, &conv) ⇒ Opt
constructor
A new instance of Opt.
- #inspect ⇒ Object
- #on(parser, store) ⇒ Object
- #required? ⇒ Boolean
Constructor Details
#initialize(cmd, name, opt, *args, desc, default: NilClass, &conv) ⇒ Opt
Returns a new instance of Opt.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dencli/cmd.rb', line 186 def initialize cmd, name, opt, *args, desc, default: NilClass, &conv @name, @desc, @default, @conv, @val, @type = name.to_s.to_sym, desc, default, conv || lambda{|v|v}, nil, nil parse_opt_string opt @type = args.pop if OptionParser.top.atype.has_key? args.last args.each &method( :parse_opt_string) @req = if NilClass != default false elsif cmd.exe.lambda? ! cmd.exe.parameters.select {|e| [:keyreq, @name] == e[0..1] }.empty? else nil end end |
Instance Attribute Details
#conv ⇒ Object (readonly)
Returns the value of attribute conv.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def conv @conv end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def desc @desc end |
#long ⇒ Object (readonly)
Returns the value of attribute long.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def long @long end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def name @name end |
#req ⇒ Object (readonly)
Returns the value of attribute req.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def req @req end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def short @short end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def type @type end |
#val ⇒ Object (readonly)
Returns the value of attribute val.
163 164 165 |
# File 'lib/dencli/cmd.rb', line 163 def val @val end |
Instance Method Details
#default ⇒ Object
166 |
# File 'lib/dencli/cmd.rb', line 166 def default() NilClass == @default ? nil : @default end |
#default? ⇒ Boolean
165 |
# File 'lib/dencli/cmd.rb', line 165 def default?() NilClass != @default end |
#inspect ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/dencli/cmd.rb', line 211 def inspect "#<%s:0x%x %s %s %s %s (%p) %p conv=%s>" % [ self.class.name, object_id, @req ? "<#{@name}>" : "[#{@name}]", @short, @long, @val, @default, @desc, @type ? " type=#{type}" : '', @exe ? "<#{@exe.lambda? ? :lambda: :proc} ##{@exe.arity}>" : "nil" ] end |
#on(parser, store) ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/dencli/cmd.rb', line 202 def on parser, store store[@name] = @default if default? short = "#{@short}#{@val ? ?= : ''}#{@val}" long = "#{@long}#{@val ? ?= : ''}#{@val}" parser.on short, long, *[@type].compact do |val| store[@name] = @conv[val] end end |
#required? ⇒ Boolean
164 |
# File 'lib/dencli/cmd.rb', line 164 def required?() @req end |