SimpleCLI
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 []
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 "\n Hello CLI\n\n Usage:\n \#{ script_name } command [options]\n\n Futher help:\n \#{ script_name } commands # list all available commands\n \#{ script_name } help <COMMAND> # show help for COMMAND\n \#{ script_name } help # show this help message\n\n"
end
def sayhello_help
"Usage: \#{ script_name } sayhello [SAY]\n\n Arguments:\n SAY: Something to say (default 'Hello World!')\n\n Summary:\n Says hello!\n"
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 []
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
command_missingmethod