class GLI::Commands::HelpModules::CommandHelpFormat
Constants
- COMMAND_HELP
Public Class Methods
new(command,app,sorter,synopsis_formatter_class,wrapper_class=TextWrapper)
click to toggle source
# File lib/gli/commands/help_modules/command_help_format.rb, line 7 def initialize(command,app,sorter,synopsis_formatter_class,wrapper_class=TextWrapper) @app = app @command = command @sorter = sorter @wrapper_class = wrapper_class @synopsis_formatter = synopsis_formatter_class.new(@app,flags_and_switches(@command,@app)) end
Public Instance Methods
format()
click to toggle source
# 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) command_examples = format_examples(@command) synopses = @synopsis_formatter.synopses_for_command(@command) COMMAND_HELP.result(binding) end
Private Instance Methods
flags_and_switches(command,app)
click to toggle source
# File lib/gli/commands/help_modules/command_help_format.rb, line 59 def flags_and_switches(command,app) if app.subcommand_option_handling_strategy == :legacy ( command.topmost_ancestor.flags_declaration_order + command.topmost_ancestor.switches_declaration_order ).select { |option| option.associated_command == command } else ( command.flags_declaration_order + command.switches_declaration_order ) end end
format_examples(command)
click to toggle source
# File lib/gli/commands/help_modules/command_help_format.rb, line 88 def format_examples(command) command.examples.map {|example| string = "" if example[:desc] string << " # #{example[:desc]}\n" end string << " #{example.fetch(:example)}\n" }.join("\n") end
format_subcommands(command)
click to toggle source
# File lib/gli/commands/help_modules/command_help_format.rb, line 73 def format_subcommands(command) commands_array = @sorter.call(command.commands_declaration_order).map { |cmd| if command.get_default_command == cmd.name [cmd.names,String(cmd.description) + " (default)"] else [cmd.names,cmd.description] end } if command.has_action? commands_array.unshift(["<default>",command.default_description]) end formatter = ListFormatter.new(commands_array,@wrapper_class) StringIO.new.tap { |io| formatter.output(io) }.string end