Class: GLI::Commands::HelpModules::OptionsFormatter

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

Instance Method Summary collapse

Constructor Details

#initialize(flags_and_switches, sorter, wrapper_class) ⇒ OptionsFormatter

Returns a new instance of OptionsFormatter.



5
6
7
8
# File 'lib/gli/commands/help_modules/options_formatter.rb', line 5

def initialize(flags_and_switches,sorter,wrapper_class)
  @flags_and_switches = sorter.call(flags_and_switches)
  @wrapper_class = wrapper_class
end

Instance Method Details

#formatObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gli/commands/help_modules/options_formatter.rb', line 10

def format
  list_formatter = ListFormatter.new(@flags_and_switches.map { |option|
    if option.respond_to? :argument_name
      [option_names_for_help_string(option,option.argument_name),description_with_default(option)]
    else
      [option_names_for_help_string(option),description_with_default(option)]
    end
  },@wrapper_class)
  stringio = StringIO.new
  list_formatter.output(stringio)
  stringio.string
end