Project

cli_base

0.0
No release in over 3 years
Low commit activity in last 3 years
Think of CLI::Base as a COM, a Commandline Object Mapper, in much the same way that ActiveRecord::Base is an ORM. A subclass of CLI::Base can define a complete command line tool using nothing more than Ruby method definitions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 13
 Project Readme

CLI::Base

Source Code | Report Issue

Gem Version

Description

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).

Synopsis

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
end

That's it. The comments above each method become the help text automatically.

Copyright

Copyright (c) 2008 Thomas Sawyer, Rubyworks

Distributed under the terms of the BSD-2-Clause license.

See COPYING.rdoc for details.