Class: L43::OptParser::Description
- Inherits:
-
Object
- Object
- L43::OptParser::Description
- Extended by:
- Core::Forwarder
- Defined in:
- lib/l43/opt_parser/description.rb
Instance Method Summary collapse
- #add_desc(*chunks, indent: 5) ⇒ Object
- #add_desc_from_file(file) ⇒ Object
- #add_flag(flag, indent: 4, color: :cyan) ⇒ Object
- #add_kwd(kwd, indent: 4, color: :cyan, vcolor: [:bold,:blue]) ⇒ Object
- #add_line(*chunks) ⇒ Object
- #add_section(text, indent: 2, color: [:bold, :green]) ⇒ Object
- #add_usage(name, options:, args:) ⇒ Object
- #lines ⇒ Object
Instance Method Details
#add_desc(*chunks, indent: 5) ⇒ Object
12 13 14 |
# File 'lib/l43/opt_parser/description.rb', line 12 def add_desc(*chunks, indent: 5) self << [indent, *chunks] end |
#add_desc_from_file(file) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/l43/opt_parser/description.rb', line 16 def add_desc_from_file(file) xcolorize_file(file).each do |colored, _| _lines << colored end self end |
#add_flag(flag, indent: 4, color: :cyan) ⇒ Object
23 24 25 26 27 |
# File 'lib/l43/opt_parser/description.rb', line 23 def add_flag(flag, indent: 4, 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: 4, color: :cyan, vcolor: [:bold,:blue]) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/l43/opt_parser/description.rb', line 29 def add_kwd(kwd, indent: 4, 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
36 37 38 |
# File 'lib/l43/opt_parser/description.rb', line 36 def add_line(*chunks) self << chunks end |
#add_section(text, indent: 2, color: [:bold, :green]) ⇒ Object
40 41 42 |
# File 'lib/l43/opt_parser/description.rb', line 40 def add_section(text, indent: 2, color: [:bold, :green]) self << [nil, indent, color, text] end |
#add_usage(name, options:, args:) ⇒ Object
44 45 46 47 48 |
# File 'lib/l43/opt_parser/description.rb', line 44 def add_usage(name, options:, args:) = "options" if == true args = "args" if args == true @__lines__ = [[:bold, "usage: ", :green, name, :reset, *_args(, [:bold, :cyan]), *_args(args, [:bold, :blue], "...")], *_lines] end |
#lines ⇒ Object
50 |
# File 'lib/l43/opt_parser/description.rb', line 50 def lines = _lines.dup.freeze |