• Stars
    star
    1,255
  • Rank 37,449 (Top 0.8 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created almost 16 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make awesome command-line applications the easy way

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.

<img src=“https://secure.travis-ci.org/davetron5000/gli.svg?branch=gli-2” alt=“Build Status” />

What Problem does GLI Solve?

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 OptionParser. 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 GLI

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.

Use

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 Gemfile:

gem "gli"

You can test your install via Bundler by running bundle exec gli help. This should produce formatted help output from GLI.

Getting Started

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 with:

  • executable 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.rb that can bootstrap your tests

  • a gemspec shell

  • a README shell

  • Rakefile that can generate RDoc, package your Gem and run tests

  • A Gemfile suitable 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

Supported Platforms

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.

Documentation

Extensive documentation is available at the wiki.

API Documentation is available here. Recommend starting with GLI::DSL or GLI::App.

Credits

Author

Dave Copeland (davetron5000 at g mail dot com)

Copyright

Copyright © 2010 by Dave Copeland

License

Distributes under the Apache License, see LICENSE.txt in the source distro

gli CLI documentation

:include:gli.rdoc

More Repositories

1

optparse-plus

Start your command line scripts off right in Ruby
Ruby
521
star
2

brutalist-web-design

Source for Brutalist Web Design
CSS
84
star
3

receta

Example deployable Rails app using AngularJS
Ruby
75
star
4

ruby-style

My personal Ruby Style Guide along with tools you can use to make your own! See usage.md
Ruby
46
star
5

angular-rails-book

Micro eBook on Getting Started with Angular on Rails
CSS
35
star
6

rails-app-template-sustainable

A Rails App Template that creates a new Rails app according to the sustainable rails book
Ruby
27
star
7

awesome-cli-ruby

Awesome Command Line Applications in Ruby Presentation
CSS
27
star
8

shorty

RESTful URL Shortener for utf-8 vanity urls, written in Scala
Scala
22
star
9

moocow

Ruby Client for Remember The Milk
Ruby
18
star
10

scala-boss

NovaJUG Presentation: "Convince your Boss to let you use Scala"
JavaScript
18
star
11

trickster

Developer-Friendly, In-Browser Presentation Software with auto-resize and syntax highlighting
CSS
17
star
12

clean_test

Write clean, understandable tests in Test::Unit
Ruby
14
star
13

ghola

Color Picker for Developers
JavaScript
14
star
14

docker-dev-template

I'm sooooo tired of googling Docker and finding shit Medium blog posts and Docker's mediocre documentation
Shell
13
star
15

hl

Highlight terms in output or files to assist with visual scanning
Ruby
11
star
16

wtf-is-a-webpack

SCSS
10
star
17

dotfiles

My various dot files
Vim Script
8
star
18

bookingit

Create code-based content based on git repos, diffs, and tags
Ruby
7
star
19

daves-resume

Move along, I'm not interested
Ruby
7
star
20

sneaking-scala

Presentation slides from my talk at ScalaDays 2010 - "Sneaking Scala Into The Enterprise"
Scala
7
star
21

event_lawyer

Prototype code to explore consumer/producer-driven contracts for messaging systems
Ruby
6
star
22

adventureclone

A clone of Atari 2600's Adventure
C++
6
star
23

oc

Make org charts with Graph Viz
Ruby
5
star
24

vimdoclet

Javadoc doclet that generates VIM helpfiles
Java
5
star
25

naildrivin5.com-OLD

My website and blog
HTML
5
star
26

weird-ruby

Presentation and code for my RubyConf talk
CSS
4
star
27

gliffy

Ruby client to Gliffy's API
Ruby
4
star
28

awesome-cli

Gem for Build Awesome Command-Line Applications in Ruby
Ruby
3
star
29

rspec_test_data

Create complex test data using factories, re-usable across multiple tests and your seed data
Ruby
3
star
30

sclassy

Scala DSL for yuml.me Class Diagrams
Scala
3
star
31

tdd_cli_talk

Slides for "Test-drive the development of your command-line applications"
Ruby
3
star
32

jruby-and-threads-talk

Presentation from my RubyNation Talk on JRuby and Threads
3
star
33

scala_tour_content

Content for Another Tour of Scala
3
star
34

importscour

Fork of ImportScrubber which normalizes import statements in Java code
Java
2
star
35

gtd

Command line app for a lightweight GTD workflow
Ruby
2
star
36

java-javadoc-vim

JDK javadoc in vimdoc format for java.* packages
2
star
37

naildrivin5.com

My Website (deployed)
HTML
2
star
38

halen

A bare-bones wiki with a Git backend, Gliffy & Disqus integration
Ruby
2
star
39

static-site-in-react

Take 2 of making a static site generator with react as templating engine
JavaScript
2
star
40

sidekiq-book

Starting App used for the Sidekiq book
Ruby
2
star
41

devbox

Shell
2
star
42

melange-css

CSS utility framework for full stack developers
CSS
2
star
43

claret

dependency-based CLI todo list app
Ruby
2
star
44

service-layer-railsconf-2022

Slides for my talk at RailsConf
JavaScript
1
star
45

restunit

A unit testing framework for REST services
Java
1
star
46

whatdavesaid.com

Source for whatdavesaid.com
HTML
1
star
47

fwf

Experiment in creating a fun web framework for Java (BTW, it failed)
Java
1
star
48

sustainable-rails.com

Website for sustainable-rails.com
HTML
1
star
49

rkarel

Ruby implementation of Karel The Robot
Ruby
1
star
50

timeline-lang.com

Website for the Timeline programming language
Handlebars
1
star
51

supercade

My old band's data-driven website in PHP (for posterity)
PHP
1
star
52

webpack2-rails

THIS IS DEAD -- DO NOT USE
Ruby
1
star
53

bookdown

Make an online book that has code that executes as you build your book
Ruby
1
star
54

javax-javadoc-vim

Javadoc in vimdoc format for javax.* packages (save javax.xml)
1
star
55

shindig

Currently theoretical event logger written in elixir
Elixir
1
star
56

you_might_are_gonna_need_it

Slides from my talk at RubyNation 2013
JavaScript
1
star
57

fullstop

Manage dotfiles
Ruby
1
star
58

fauxml

Indented file-to-xml transcoder for hand-authoring annoying Java XML files
Java
1
star