module Webgen::CLI

Namespace for all classes that act as CLI commands.

Implementing a CLI command

A CLI command is an extension that can be invoked from the webgen CLI 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.gettalong.org!

Sample CLI command extension

Here is a sample CLI command extension:

class SampleCommand < CmdParse::Command

  def initialize
    super('sample', takes_commands: false)
    short_desc("This sample command just outputs its parameters")
    description("Uses the global verbosity level and outputs additional information when " +
                  "the level is set to verbose!")
    @username = nil
    options.on('-u', '--user USER', String, 'Specify an additional user name to output') do |username|
      @username = username
    end
  end

  def execute(required, *optional)
    puts "Command line arguments:"
    ([required] + optional).each {|arg| puts arg}
    if command_parser.log_level <= 1
      puts "Some debug information here"
    end
    puts "The entered username: #{@username}" if @username
  end

end

website.ext.cli.add_command(SampleCommand.new)

The Webgen::CLI::Utils module provides some useful methods for outputting formatted or highlighted text.