Class: Argy::Help

Inherits:
Object
  • Object
show all
Defined in:
lib/argy/help.rb

Overview

Builds help information

Instance Method Summary collapse

Constructor Details

#initialize(parser, column: 30, color: $stdout.tty?) ⇒ Help

Create a new Help

Parameters:

  • parser (Parser)

    the parser to generate help for

  • column (Integer) (defaults to: 30)

    the column width of the help

  • color (TrueClass, FalseClass) (defaults to: $stdout.tty?)

    whether or not to print with color



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

Parameters:

  • name (String)

    left column of the entry

  • desc (String) (defaults to: nil)

    right column of the entry

  • required (TrueClass, FalseClass) (defaults to: false)

    whether or not the entry is required

  • default (Object) (defaults to: nil)

    default value for the entry

Returns:

  • (String)


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

Returns:

  • (String)


31
32
33
# File 'lib/argy/help.rb', line 31

def section(title)
  bold "\n#{title}"
end

#to_sString

The help information

Returns:

  • (String)


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)
  options(out)
  flags(out)

  out.join("\n") + "\n"
end