CLI::Base is a quick-and-dirty CLI framework for Ruby. Need a command-line
interface without the ceremony? Just subclass CLI::Base and define methods —
writer methods (=) become options, query methods (?) become flags, and
nested classes become subcommands. No DSL to learn.
Think of it as a COM (Command-to-Object Mapper).
require 'cli/base'
class MyCLI < 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= :include=
# 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
endThat's it. The comments above each method become the help text automatically.
Copyright (c) 2008 Thomas Sawyer, Rubyworks
Distributed under the terms of the BSD-2-Clause license.
See COPYING.rdoc for details.