Class: DenCli::CMD::Opt

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#convObject (readonly)

Returns the value of attribute conv.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def conv
  @conv
end

#descObject (readonly)

Returns the value of attribute desc.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def desc
  @desc
end

#longObject (readonly)

Returns the value of attribute long.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def long
  @long
end

#nameObject (readonly)

Returns the value of attribute name.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def name
  @name
end

#reqObject (readonly)

Returns the value of attribute req.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def req
  @req
end

#shortObject (readonly)

Returns the value of attribute short.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def short
  @short
end

#typeObject (readonly)

Returns the value of attribute type.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def type
  @type
end

#valObject (readonly)

Returns the value of attribute val.



163
164
165
# File 'lib/dencli/cmd.rb', line 163

def val
  @val
end

Instance Method Details

#defaultObject



166
# File 'lib/dencli/cmd.rb', line 166

def default() NilClass == @default ? nil : @default end

#default?Boolean

Returns:

  • (Boolean)


165
# File 'lib/dencli/cmd.rb', line 165

def default?() NilClass != @default end

#inspectObject



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

Returns:

  • (Boolean)


164
# File 'lib/dencli/cmd.rb', line 164

def required?() @req end