Class: Cri::HelpRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/cri/help_renderer.rb

Overview

The HelpRenderer class is responsible for generating a string containing the help for a given command, intended to be printed on the command line.

Constant Summary collapse

LINE_WIDTH =

The line width of the help output

78
DESC_INDENT =

The indentation of descriptions

4
OPT_DESC_SPACING =

The spacing between an option name and option description

6

Instance Method Summary collapse

Constructor Details

#initialize(cmd, **params) ⇒ HelpRenderer

Creates a new help renderer for the given command.

Parameters:

  • cmd (Cri::Command)

    The command to generate the help for

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :verbose (Boolean)

    true if the help output should be verbose, false otherwise.



22
23
24
25
26
# File 'lib/cri/help_renderer.rb', line 22

def initialize(cmd, **params)
  @cmd        = cmd
  @is_verbose = params.fetch(:verbose, false)
  @io         = params.fetch(:io, $stdout)
end

Instance Method Details

#renderString

Returns The help text for this command.

Returns:

  • (String)

    The help text for this command



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cri/help_renderer.rb', line 29

def render
  text = +''

  append_summary(text)
  append_usage(text)
  append_description(text)
  append_subcommands(text)
  append_options(text)

  text
end