Class: Argy::Help
- Inherits:
-
Object
- Object
- Argy::Help
- Defined in:
- lib/argy/help.rb
Overview
Builds help information
Instance Method Summary collapse
-
#entry(name, desc: nil, required: false, default: nil) ⇒ String
Format an entry of a section.
-
#initialize(parser, column: 30, color: $stdout.tty?) ⇒ Help
constructor
Create a new Help.
-
#section(title) ⇒ String
Format the title of a custom section.
-
#to_s ⇒ String
The help information.
Constructor Details
#initialize(parser, column: 30, color: $stdout.tty?) ⇒ Help
Create a new Help
8 9 10 11 12 |
# File 'lib/argy/help.rb', line 8 def initialize(parser, column: 30, color: $stdout.tty?) @parser = parser @column = column @color = color end |
Instance Method Details
#entry(name, desc: nil, required: false, default: nil) ⇒ String
Format an entry of a section
41 42 43 44 45 46 47 |
# File 'lib/argy/help.rb', line 41 def entry(name, desc: nil, required: false, default: nil) out = " #{name.ljust(column)}" out += dim("#{desc} ") if desc out += dim("(required) ") if required out += dim("[default: #{default.inspect}]") if default out.rstrip end |
#section(title) ⇒ String
Format the title of a custom section
31 32 33 |
# File 'lib/argy/help.rb', line 31 def section(title) bold "\n#{title}" end |
#to_s ⇒ String
The help information
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/argy/help.rb', line 16 def to_s out = [] description(out) usage(out) examples(out) arguments(out) (out) flags(out) out.join("\n") + "\n" end |