Class: GLI::Commands::HelpModules::GlobalHelpFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/gli/commands/help_modules/global_help_format.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, sorter, wrapper_class) ⇒ GlobalHelpFormat

Returns a new instance of GlobalHelpFormat.



7
8
9
10
11
# File 'lib/gli/commands/help_modules/global_help_format.rb', line 7

def initialize(app,sorter,wrapper_class)
  @app = app
  @sorter = sorter
  @wrapper_class = wrapper_class
end

Instance Method Details

#formatObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gli/commands/help_modules/global_help_format.rb', line 13

def format
  program_desc = @app.program_desc
  program_long_desc = @app.program_long_desc
  if program_long_desc
    wrapper = @wrapper_class.new(Terminal.instance.size[0],4)
    program_long_desc = "\n    #{wrapper.wrap(program_long_desc)}\n\n" if program_long_desc
  else
    program_long_desc = "\n"
  end

  command_formatter = ListFormatter.new(@sorter.call(@app.commands_declaration_order.reject(&:nodoc)).map { |command|
    [[command.name,Array(command.aliases)].flatten.join(', '),command.description]
  }, @wrapper_class)
  stringio = StringIO.new
  command_formatter.output(stringio)
  commands = stringio.string

  global_option_descriptions = OptionsFormatter.new(global_flags_and_switches,@sorter,@wrapper_class).format

  GLOBAL_HELP.result(binding)
end