Class Index [+]

Quicksearch

Ramaze::Bin::Runner

Module used for running a particular command based on the specified command line arguments.

Usage:

   ramaze --help # Shows a help message
   ramaze -h     # Shows a help message as well
   ramaze -v     # Shows the version of Ramaze

   ramaze [COMMAND] # Runs [COMMAND]

@author Yorick Peterse @since 21-07-2011

Constants

Commands

Hash containing all the available commands, their names and their classes.

Banner

String containing the banner of the main command.

Public Class Methods

commands_info() click to toggle source

Generates an array of “rows” where each row contains the name and description of a command. The descriptions of all commands are aligned based on the length of the longest command name.

@author Yorick Peterse @since 21-07-2011 @return [Array]

     # File lib/ramaze/bin/runner.rb, line 115
115:       def self.commands_info
116:         cmds    = []
117:         longest = Commands.map { |name, klass| name.to_s }.sort[0].size
118: 
119:         Commands.each do |name, klass|
120:           name = name.to_s
121:           desc = ''
122: 
123:           # Try to extract the command description
124:           if klass.respond_to?(:const_defined?)            and klass.const_defined?(:Description)
125:             desc = klass.const_get(:Description)
126:           end
127: 
128:           # Align the description based on the length of the name
129:           while name.size <= longest do
130:             name += ' '
131:           end
132: 
133:           cmds.push(["#{name}    #{desc}"])
134:         end
135: 
136:         return cmds
137:       end
run(argv=ARGV) click to toggle source

Runs a particular command based on the specified array.

@example

 Ramaze::Bin::Runner.run(ARGV)
 Ramaze::Bin::Runner.run(['start', '--help'])

@author Yorick Peterse @since 21-07-2011 @param [Array] argv An array containing command line arguments, set to

 ARGV by default.
     # File lib/ramaze/bin/runner.rb, line 66
 66:       def self.run(argv=ARGV)
 67:         op = OptionParser.new do |opt|
 68:           opt.banner         = Banner
 69:           opt.summary_indent = '  '
 70: 
 71:           opt.separator "\nCommands:\n  #{commands_info.join("\n  ")}"
 72: 
 73:           # Show all the common options
 74:           opt.separator "\nOptions:\n"
 75: 
 76:           # Show the version of Ramaze
 77:           opt.on('-v', '--version', 'Shows the version of Ramaze') do
 78:             puts Ramaze::VERSION
 79:             exit
 80:           end
 81: 
 82:           opt.on('-h', '--help', 'Shows this help message') do
 83:             puts op
 84:             exit
 85:           end
 86:         end
 87: 
 88:         op.order!(argv)
 89: 
 90:         # Show a help message if no command has been specified
 91:         if !argv[0]
 92:           puts op.to_s
 93:           exit
 94:         end
 95: 
 96:         cmd = argv.delete_at(0).to_sym
 97: 
 98:         if Commands.key?(cmd)
 99:           cmd = Commands[cmd].new
100:           cmd.run(argv)
101:         else
102:           abort 'The specified command is invalid'
103:         end
104:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.