Class: Cri::HelpRenderer — Documentation by YARD 0.9.34

# Class: Cri::HelpRenderer

Inherits:
  Object
  - Object
  - Cri::HelpRenderer
  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

- #initialize(cmd, **params) ⇒ HelpRenderer constructor

  Creates a new help renderer for the given command.

- #render ⇒ String

  The help text for this command.

## 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

### #render ⇒ `String`

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