Website | Source Code | Report Issue | #rubyworks
<img src=“http://travis-ci.org/rubyworks/cli_base.png” />
CLI::Base is a very striaght-forward CLI framework for Ruby. CLI::Base is a COM Command-to-Object Mapping library. A command line tool can be defined using nothing more than Ruby’s own standard syntax. No special DSL is required.
IMPORTANT! CLI::Base’s help feature is Ruby 1.9+ only. It does NOT support 1.8.7 or older.
Using CLI::Base is straight-forward. Simply subclass the CLI::Base base class and add methods to handle command-line options. Writer methods (those ending in ‘=’) coorepsond to an option and a query method (ending in ‘?’) marks an option a flag. For example, here is a simple commandline tool to run a Ruby script.
require 'cli/base' class RunCLI < CLI::Base # Require LIBRARY before executing your script. def require=(lib) require lib end alias :r= :require= # Include PATH in $LOAD_PATH. def include=(path) $:.unshift path end alias :I= :incude # Run in DEBUG mode. def debug? $DEBUG = true end # Show this message. def help? puts self exit end alias :h? :help? # Run the command. def main(script) load(script) end end
For a more detail example see EXAMPLE.md.
Copyright © 2009 Rubyworks.
This program is distributed under the terms of the BSD-2-Clause license.
Please see COPYING.rdoc file for details.