Class: L43::OptParser::Description

Inherits:
Object
  • Object
show all
Defined in:
lib/l43/opt_parser/description.rb

Instance Method Summary collapse

Instance Method Details

#add_desc(*chunks, indent: 5) ⇒ Object



8
9
10
# File 'lib/l43/opt_parser/description.rb', line 8

def add_desc(*chunks, indent: 5)
  self << [indent, *chunks]
end

#add_flag(flag, indent: 3, color: :cyan) ⇒ Object



12
13
14
15
16
# File 'lib/l43/opt_parser/description.rb', line 12

def add_flag(flag, indent: 3, color: :cyan)
  return unless flag.desc
  short = flag.short ? ":#{flag.short}|" : ""
    self <<  [indent, color, short, ":", flag.name.to_s, :reset, 1, flag.desc ] 
end

#add_kwd(kwd, indent: 3, color: :cyan, vcolor: [:bold,:blue]) ⇒ Object



18
19
20
21
22
23
# File 'lib/l43/opt_parser/description.rb', line 18

def add_kwd(kwd, indent: 3, color: :cyan, vcolor: [:bold,:blue])
  return unless kwd.desc
  short = kwd.short ? "#{kwd.short}:|" : ""
  default = kwd.default == Core::None ? [] : [1, :dim, "defaults to: ", :bold, kwd.default.inspect]
  self << [indent, color, short, kwd.name.to_s, ": ", vcolor, "<value>", :reset, 1, kwd.desc, *default] 
end

#add_line(*chunks) ⇒ Object



25
26
27
# File 'lib/l43/opt_parser/description.rb', line 25

def add_line(*chunks)
  self << chunks
end

#add_section(text, indent: 1, color: [:bold, :green]) ⇒ Object



29
30
31
# File 'lib/l43/opt_parser/description.rb', line 29

def add_section(text, indent: 1, color: [:bold, :green])
  self << [nil, indent, color, text]
end

#add_usage(name, options:, args:) ⇒ Object



33
34
35
36
37
# File 'lib/l43/opt_parser/description.rb', line 33

def add_usage(name, options:, args:)
  options = "options" if options == true
  args = "args" if args == true
  @__lines__ = [[:bold, name, " ", *_args(options, [:bold, :cyan]), ' ', *_args(args, [:bold, :blue], "...")], *_lines]
end

#linesObject



39
# File 'lib/l43/opt_parser/description.rb', line 39

def lines = _lines.dup.freeze