Class: Cl::Help::Format::Opt

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Regex

#format_regex

Instance Attribute Details

#optObject

Returns the value of attribute opt

Returns:

  • (Object)

    the current value of opt


26
27
28
# File 'lib/cl/help/format.rb', line 26

def opt
  @opt
end

Instance Method Details

#formatObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cl/help/format.rb', line 29

def format
  opts = []
  opts << "alias: #{format_aliases(opt)}" if opt.aliases?
  opts << "requires: #{opt.requires.join(', ')}" if opt.requires?
  opts << "default: #{format_default(opt)}" if opt.default?
  opts << "known values: #{format_enum(opt)}" if opt.enum?
  opts << "format: #{opt.format}" if opt.format?
  opts << "downcases" if opt.downcase?
  opts << "upcases" if opt.upcase?
  opts << "min: #{opt.min}" if opt.min?
  opts << "max: #{opt.max}" if opt.max?
  opts << "e.g.: #{opt.example}" if opt.example?
  opts << "note: #{opt.note}" if opt.note?
  opts << "see: #{opt.see}" if opt.see?
  opts << format_deprecated(opt) if opt.deprecated?
  opts.compact
end

#format_aliases(opt) ⇒ Object


47
48
49
50
51
52
53
# File 'lib/cl/help/format.rb', line 47

def format_aliases(opt)
  opt.aliases.map do |name|
    strs = [name]
    strs << "(deprecated, please use #{opt.name})" if opt.deprecated[0] == name
    strs.join(' ')
  end.join(', ')
end

#format_default(opt) ⇒ Object


59
60
61
# File 'lib/cl/help/format.rb', line 59

def format_default(opt)
  opt.default.is_a?(Symbol) ? opt.default.to_s.sub('_', ' ') : opt.default
end

#format_deprecated(opt) ⇒ Object


63
64
65
# File 'lib/cl/help/format.rb', line 63

def format_deprecated(opt)
  return "deprecated (#{opt.deprecated[1]})" if opt.deprecated[0] == opt.name
end

#format_enum(opt) ⇒ Object


55
56
57
# File 'lib/cl/help/format.rb', line 55

def format_enum(opt)
  opt.enum.map { |value| format_regex(value) }.join(', ')
end