Class: Cl::Help::Format::Obj

Inherits:
Struct
  • Object
show all
Defined in:
lib/cl/help/format.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objObject

Returns the value of attribute obj

Returns:

  • (Object)

    the current value of obj



8
9
10
# File 'lib/cl/help/format.rb', line 8

def obj
  @obj
end

Instance Method Details

#formatObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/cl/help/format.rb', line 9

def format
  opts = []
  opts << "type: #{type(obj)}" unless obj.type == :flag
  opts << 'required' if obj.required?
  opts += Opt.new(obj).format if obj.is_a?(Cl::Opt)
  opts = opts.join(', ')
  opts = "(#{opts})" if obj.description && !opts.empty?
  opts = [obj.description, opts]
  opts.compact.map(&:strip).join(' ')
end

#type(obj) ⇒ Object



20
21
22
23
# File 'lib/cl/help/format.rb', line 20

def type(obj)
  return obj.type unless obj.is_a?(Cl::Opt) && obj.type == :array
  "array (string, can be given multiple times)"
end