Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple CLI application development library (Ruby)
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
simplecli2
simplecli3
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION.yml
simplecli.gemspec

README.rdoc

SimpleCLI

UNDERGOING RENOVATIONS !!

SimpleCLI is Undergoing Renovations

After over a year of use, this library needs some love!

I'm going to …

  • get a spec suite working again (I had specs for SimpleCLI once … they're gone now)

  • create a DSL (or 2) for making it easier for people to make SimpleCLI apps if they don't want to just include the SimpleCLI module in one of their classes

  • make (atleast some of) the DSL work in pre-defined classes (kindof like what we do now)

  • create a screencast showing how easy it is to use SimpleCLI (and how to test-drive SimpleCLI applications)

  • document #command_missing and #default_comment usage with good examples

  • create abunchof examples and throw them in the examples directory

  • add #before and #after blocks for handling global options or something to do before exiting type stuff

  • make sure errors return the right response code

About

Super Simple RubyGems-like CLI

SimpleCLI gives you a stupidly simple way to implement command-line interfaces like that of RubyGems with a basic interface like:

gem command [options]

SimpleCLI gives you a way of defining your commands (or actions) so they'll automatically show up when you run `yourapp commands`

SimpleCLI also makes it really easy to add documentation to each of your commands (or actions)

Real Examples

I use SimpleCLI in most of my apps for quick and dirty command-line interfaces.

Here are a few real examples:

Example

Here's a super simple SimpleCLI example:

#! /usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/simplecli'

class Hello
  include SimpleCLI

  def usage
    puts <<doco

  Hello CLI

    Usage:
      #{ script_name } command [options]

    Futher help:
      #{ script_name } commands         # list all available commands
      #{ script_name } help <COMMAND>   # show help for COMMAND
      #{ script_name } help             # show this help message

doco
  end

  def sayhello_help
    <<doco
Usage: #{ script_name } sayhello [SAY]

  Arguments:
    SAY:         Something to say (default 'Hello World!')

  Summary:
    Says hello!
doco
  end
  def sayhello *args
    puts args.empty? ? "Hello World!" : args.join(' ')
  end

end

# POSTAMBLE
if __FILE__ == $0
  Hello.new( ARGV, :default => 'sayhello' ).run
end

Example usage:

$ ./hello-cli

Hello CLI

  Usage:
    hello-cli command [options]

  Futher help:
    hello-cli commands         # list all available commands
    hello-cli help <COMMAND>   # show help for COMMAND
    hello-cli help             # show this help message

$ ./hello-cli commands

hello-cli commands are:

    DEFAULT COMMAND   sayhello

    commands          List all 'hello-cli' commands
    help              Provide help documentation for a command
    sayhello          Says hello!

For help on a particular command, use 'hello-cli help COMMAND'.

$ ./hello-cli help

Usage: hello-cli help COMMAND

  Summary:
    Provide help documentation for a command

$ ./hello-cli help sayhello

Usage: hello-cli sayhello [SAY]

  Arguments:
    SAY:         Something to say (default 'Hello World!')

  Summary:
    Says hello!

$ ./hello-cli sayhello

Hello World!

$ ./hello-cli sayhello Hi There

Hi There

$ ./hello-cli Hi There `# this works because sayhello is configured as the default command`

Hi There

TODO


* implement a `before` block for handling global options
* there was once a spec suite ... where'd it go?  find or recreate it!
Something went wrong with that request. Please try again.