Class: CTioga2::Commands::Documentation::CommandLineHelp

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/commands/doc/help.rb

Overview

Displays help about command-line options and such.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandLineHelp

Returns a new instance of CommandLineHelp.



32
33
34
# File 'lib/ctioga2/commands/doc/help.rb', line 32

def initialize
  @options_column_width = 20
end

Instance Attribute Details

#options_column_widthObject

How much space to leave for the options ?



30
31
32
# File 'lib/ctioga2/commands/doc/help.rb', line 30

def options_column_width
  @options_column_width
end

Instance Method Details

Prints short help text suitable for a –help option about available commands, by groups (ungrouped last). It takes a list of all commands (cmds) and the list of groups to display.

TODO: word splitting.

TODO: why not try color, too ;-) ???



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ctioga2/commands/doc/help.rb', line 44

def print_commandline_options(cmds, groups)
  for group in groups
    puts unless group == groups[0]
    name = (group && group.name) || "Ungrouped commands"
    if group && group.blacklisted 
      name << " (blacklisted)"
    end
    puts name
    for cmd in cmds[group].sort {|a,b|
        a.long_option <=> b.long_option
      }

      strings = cmd.option_strings
      puts "#{leading_spaces}%2s%1s %-#{@options_column_width}s%s" % 
        [ 
         strings[0], (strings[0] ? "," : " "),
         strings[1],
         if strings[1].size >= @options_column_width
           "\n#{total_leading_spaces}#{strings[2]}"
         else
           strings[2]
         end
        ]
      if cmd.has_options?
        puts "#{total_leading_spaces}  options: %s" %
          cmd.optional_arguments.keys.sort.map {|x| "/#{x}"}.join(' ')
      end
    end
  end

end