Class: GLI::Commands::Help

Inherits:
Command
  • Object
show all
Defined in:
lib/na/help_monkey_patch.rb

Overview

Help Command Monkeypatch for paginated output

Instance Method Summary collapse

Instance Method Details

#show_help(_global_options, options, arguments, out, error) ⇒ void

This method returns an undefined value.

Show help output for GLI commands with paginated output

Examples:

GLI::Commands::Help.new.show_help({}, {}, [], $stdout, $stderr)

Parameters:

  • _global_options (Hash)

    Global CLI options

  • options (Hash)

    Command-specific options

  • arguments (Array)

    Command arguments

  • out (IO)

    Output stream

  • error (IO)

    Error stream



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/na/help_monkey_patch.rb', line 24

def show_help(_global_options, options, arguments, out, error)
  NA::Pager.paginate = true

  command_finder = HelpModules::CommandFinder.new(@app, arguments, error)
  if options[:c]
    help_output = HelpModules::HelpCompletionFormat.new(@app, command_finder, arguments).format
    out.puts help_output unless help_output.nil?
  elsif arguments.empty? || options[:c]
    NA::Pager.page HelpModules::GlobalHelpFormat.new(@app, @sorter, @text_wrapping_class).format
  else
    name = arguments.shift
    command = command_finder.find_command(name)
    unless command.nil?
      NA::Pager.page HelpModules::CommandHelpFormat.new(
        command,
        @app,
        @sorter,
        @synopsis_formatter_class,
        @text_wrapping_class
      ).format
    end
  end
end