GLI, the Git-Like Interface Command Line Parser
GLI allows you to create command-line app in Ruby that behaves like
git in that it takes subcommands to perform a series of complex action, e.g.
git remote add.
What Problem does
Creating a command-line app that uses subcommands, each of which might accept different command-line options, is somewhat difficult with Ruby's built-in
GLI provides an API that wraps
OptionParser so that you can create a subcommand-based command-line app with minimal boilerplate. This API also produces complete documentation for your command-line app.
Why is GLI's solution different from others?
There are other RubyGems that allow you to create a command-line app that takes subcommands. These solutions are often quite limited (e.g. they don't allow deeply nested subcommand structures or sophisticated command-line options per subcommand), or require more code that we think is needed. Some solutions make it difficult or impossible to properly document your command-line app.
What you need to know to use
You should know Ruby, and have a basic understanding of how the UNIX command line works: standard input, standard output, standard error, and exit codes.
Install if you need to:
gem install gli
You can validate you have installed it correctly by running
gli help. You should see formatted help output.
If you are using
GLI in another application, add it to your
You can test your install via Bundler by running
bundle exec gli help. This should produce formatted help output from
The simplest way to get started is to create a scaffold project
gli init todo list add complete
(note if you installed via Bundler you will need to execute
bundle exec gli init todo list add complete)
This will create a basic scaffold project in
./todo/bin/todo. This file demonstrates most of what you need to describe your command line interface.
an empty test in
./todo/test/default_test.rbthat can bootstrap your tests
a gemspec shell
a README shell
Rakefile that can generate RDoc, package your Gem and run tests
Gemfilesuitable for use with Bundler to manage development-time dependencies
Now, you are ready to go:
> cd todo > bundle exec bin/todo help NAME todo - Describe your application here SYNOPSIS todo [global options] command [command options] [arguments...] VERSION 0.0.1 GLOBAL OPTIONS -f, --flagname=The name of the argument - Describe some flag here (default: the default) --help - Show this message -s, --[no-]switch - Describe some switch here COMMANDS add - Describe add here complete - Describe complete here help - Shows a list of commands or help for one command list - Describe list here > bundle exec bin/todo help list NAME list - Describe list here SYNOPSIS todo [global options] list [command options] Describe arguments to list here COMMAND OPTIONS -f arg - Describe a flag to list (default: default) -s - Describe a switch to list
All you need to do is fill in the documentation and your code; the help system, command-line parsing and many other awesome features are all handled for you.
Get a more detailed walkthrough on the main site
See `.circleci/config.yml` for the supported rubies, but general we're running tests on the all MRI rubies receiving support, which tends to be the most recent four versions.
GLI should work on older Rubies and JRuby, but it's too much work to keep tests passing for those.
Extensive documentation is available at the wiki.
Dave Copeland (davetron5000 at g mail dot com)
Copyright © 2010 by Dave Copeland
Distributes under the Apache License, see LICENSE.txt in the source distro
Source on GitHub
gli CLI documentation
gli - create scaffolding for a GLI-powered application
Root dir of project
- Default Value
This is the directory where the project''s directory will be made, so if you
specify a project name ''foo'' and the root dir of ''.'', the directory ''./foo'' will be created'
Show this message
Dry run; dont change the disk
Display the program version
Shows a list of commands or help for one command
Gets help for the application or its commands. Can also list the commands in a way helpful to creating a bash-style completion function
List commands one per line, to assist with shell completion
init|scaffold project_name [command_name]...
Create a new GLI-based project
This will create a scaffold command line project that uses
for command line processing. Specifically, this will create an executable ready to go, as well as a lib and test directory, all inside the directory named for your project
Create an ext dir
Overwrite/ignore existing files and directories
Do not create a test or features dir
Create an .rvmrc based on your current RVM setup