Namespace for all classes that act as CLI commands.
Each CLI command class needs to be put into this module and has to end with Command, otherwise it is not used. A CLI command is an extension that can be invoked from the webgen command and thus needs to be derived from CmdParse::Command. For detailed information on this class and the whole cmdparse package have a look at cmdparse.rubyforge.org!
Here is a sample CLI command extension which could be put, for example, into the ext/init.rb of a webgen website:
require 'webgen/cli' class Webgen::CLI::SampleCommand < CmdParse::Command def initialize super('sample', false) self.short_desc = "This sample command just outputs its parameters" self.description = Webgen::CLI::Utils.format("Uses the global verbosity level and outputs additional " + "information when the level is set to verbose!") @username = nil self.options = CmdParse::OptionParserWrapper.new do |opts| opts.separator "Options:" opts.on('-u', '--user USER', String, 'Specify an additional user name to output') {|username| @username = username} end end def execute(args) if args.length == 0 raise OptionParser::MissingArgument.new('ARG1 [ARG2 ...]') else puts "Command line arguments:" args.each {|arg| puts arg} if commandparser.verbosity == :verbose puts "Yeah, some additional information is always cool!" end puts "The entered username: #{@username}" if @username end end end
Note the use of Webgen::CLI::Utils.format in the initialize method so that the long text gets wrapped correctly! The Utils class provides some other useful methods, too!
For information about which attributes are available on the webgen command parser instance have a look at Webgen::CLI::CommandParser!
Generated with the Darkfish Rdoc Generator 2.