Class: GLI::Commands::HelpModules::CommandHelpFormat

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

Instance Method Summary collapse

Constructor Details

#initialize(command, app, basic_invocation, sorter, wrapper_class = TextWrapper) ⇒ CommandHelpFormat

Returns a new instance of CommandHelpFormat.



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

def initialize(command,app,basic_invocation,sorter,wrapper_class=TextWrapper)
  @basic_invocation = basic_invocation
  @app = app
  @command = command
  @sorter = sorter
  @wrapper_class = wrapper_class
end

Instance Method Details

#formatObject



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

def format
  command_wrapper      = @wrapper_class.new(Terminal.instance.size[0],4 + @command.name.to_s.size + 3)
  wrapper              = @wrapper_class.new(Terminal.instance.size[0],4)
  
  options_description  = OptionsFormatter.new(flags_and_switches(@command,@app),@sorter,@wrapper_class).format
  commands_description = format_subcommands(@command)

  synopses = []
  one_line_usage = basic_usage
  one_line_usage << @command.arguments_description
  if @command.commands.empty?
    synopses << one_line_usage
  else
    synopses = sorted_synopses
    if @command.has_action?
      synopses.unshift(one_line_usage)
    end

  end

  COMMAND_HELP.result(binding)
end