• Stars
    star
    19
  • Rank 1,124,131 (Top 23 %)
  • Language
    Ruby
  • License
    Other
  • Created about 14 years ago
  • Updated almost 14 years ago

Reviews

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

Repository Details

Ruby command line argument parser

clint(7) -- Ruby command line argument parser

SYNOPSIS

require 'clint'
c = Clint.new
c.usage do
  $stderr.puts "Usage: #{File.basename(__FILE__)} [-h|--help]"
end
c.help do
  $stderr.puts "  -h, --help\tshow this help message"
end
c.options :help => false, :h => :help
c.parse ARGV
if c.options[:help]
  c.help
  exit 1
end
c.dispatch Callable
c.subcommand Klass

DESCRIPTION

Clint is an alternative Ruby command line argument parser that's very good for programs using the subcommand pattern familiar from git(1), svn(1), apt-get(8), and many others. In addition, it separates option declarations from usage and help messages becuase the author feels like that's a better idea.

Clint options are declared by passing hash arguments to Clint#options. The hash keys should be Symbols. If the value is also a Symbol, an alias is defined from the key to the value. If the value is a Class, Clint attempts to find a default value for that class. Otherwise, the value is treated as the default and the value's class will be used to construct type-accurate values from command line arguments.

Clint#options may be called repeatedly to declare extra options and aliases. Clint#reset can be used at any time to clear all declared options and aliases.

Clint#parse may likewise be called repeatedly. At the end of each invocation, it stores the remaining non-option arguments, meaning that arguments (for example, ARGV) must only be passed as a parameter to the first invocation.

Clint#dispatch may be called after Clint#parse with a callable that will receive the arguments and options. If there is a mismatch in the arity of the callable's #call method, the callable's constructor is called with no arguments and the resulting object is treated as the callable that receives the arguments and options.

Clint#subcommand may be called after Clint#parse to automatically handle the subcommand pattern as follows. The first non-option argument is taken to be the subcommand, which must exist as a singleton or instance method of the class object passed to Clint#subcommand. If a suitable class method is found, it is called with all remaining arguments, including a hash of the parsed options if we can get away with it. Otherwise, an instance is constructed with the next non-option argument and the instance method is called with all remaining arguments, again including a hash of the parsed options if we can get away with it.

Due to limitations in the Ruby 1.8 grammar, all methods that could act as subcommands must not declare default argument values except options={} if desired.

THEME SONG

Leo Arnaud and John Williams - "Bugler's Dream"

AUTHOR

Richard Crowley [email protected]

SEE ALSO

The standard Ruby OptionParser class http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html.

More Repositories

1

go-metrics

Go port of Coda Hale's Metrics library
Go
3,421
star
2

goagain

Zero-downtime restarts in Go
Go
2,080
star
3

go-tigertonic

A Go framework for building JSON web services inspired by Dropwizard
Go
995
star
4

certified

Generate and manage an internal CA for your company
HTML
416
star
5

freight

A modern take on the Debian archive.
Shell
401
star
6

slack

Run a command; post it and its standard input, output, and error to Slack
Shell
109
star
7

json.sh

Pure-shell JSON parser
Shell
94
star
8

mustache.sh

Mustache in POSIX shell
Shell
81
star
9

gitpaid

The programmer's time tracker
Shell
64
star
10

django-twitterauth

Use Twitter for authentication in Django
Python
56
star
11

go-librato

Go client for Librato Metrics
Go
52
star
12

puppet-pip

DON'T USE THIS, USE PUPPET 2.7
Ruby
33
star
13

debra

build Debian packages
Shell
30
star
14

bashpress

Command-line blog engine
PHP
26
star
15

opendns-fetchstats

Automatically fetch your OpenDNS Top Domains data
Visual Basic
18
star
16

rcrowley

My home directory and
JavaScript
18
star
17

puppet-related_nodes

An alternative to Puppet's exported resources
Ruby
16
star
18

pagerunit

A simple Nagios alternative made to look like unit tests.
Python
9
star
19

curvr

Automatic approximation of typical Photoshop actions
C++
8
star
20

archiso

Branch of https://projects.archlinux.org/archiso.git that supports unattended installation
Shell
6
star
21

manskeleton

build skeleton man paths
6
star
22

gas

Gas is a tiny prefork WSGI server and app for streaming static files through grep-, awk- and sed-like generators.
Python
6
star
23

dopploadr

A Flickr Uploadr extension for geotagging photos with Dopplr trips.
JavaScript
6
star
24

extending-puppet

Example code from my Extending Puppet talk
Ruby
6
star
25

puppet-python

5
star
26

fpf

Effing package format!
Shell
5
star
27

upstartable-nginx

Shell
5
star
28

go-shellac

Very experimental experiment into a declarative, strongly-typed API for executing shell commands from Go
Go
5
star
29

wheresmycar

Scrapes SF GIS to send alerts when I need to move my car for street cleaning
PHP
5
star
30

thrudb

Modifications to the Thrudb storage engine built on Thrift.
C++
4
star
31

sometimes

a PHP templating system
PHP
4
star
32

powncefs

A Fuse filesystem for your friends' files on Pownce
Python
4
star
33

hapimoney

Django implementation of HapiMoney
Python
3
star
34

puppet-crunkd

3
star
35

puppet-ruby

3
star
36

spoon

Spoon feeds HTML5 into Atom.
Python
3
star
37

go-bson

Not just a mirror of http://labix.org/gobson
Go
3
star
38

talk-django-puppet

Deploying Django with Puppet
JavaScript
3
star
39

puppet-sourceinstall

3
star
40

ssh-freeagent

Shell
3
star
41

nomblr

Python
3
star
42

puppet-virtualbox

Shell
3
star
43

httperf_modified

httperf with percentiles
Shell
3
star
44

talk-developing-operability

JavaScript
2
star
45

mixinstall

Manage read-only "mixed projects" within your own
2
star
46

countd

DON'T USE THIS. It's an old experiment and I wanted to free up some space in my GitHub account.
Python
2
star
47

lazy_redis

Maybe this is not a terrible idea?
Ruby
2
star
48

puppet-interfaces

Legacy repository for reclaiming some lost bug fixes
Ruby
2
star
49

talk-blueprint

JavaScript
2
star
50

slack-gmail-screener

Get mentioned in Slack when you receive email from noteworthy senders; don't be bothered with the rest
Python
2
star
51

talk-extending-puppet

JavaScript
2
star
52

krecipec

Ruby
2
star
53

python-givvy

Python bindings to the Givvy API
2
star
54

errforce

Utilities for working effectively with Go errors and UNIX errnos
Go
1
star
55

fsevents

Mirror of Yossef Mendelssohn's probably defunct fsevents gem
Ruby
1
star
56

puppet-iptables

Puppet
1
star
57

talk-securing-and-extending-puppet

Securing and Extending Puppet talk
JavaScript
1
star
58

talk-why-is-config-mgmt-ruby

JavaScript
1
star
59

rcrowley.github.com

1
star
60

puppet-php

1
star
61

talk-dep-mgmt-with-puppet

Dependency Management with Puppet lightning talk
JavaScript
1
star
62

gimmeservers

Python
1
star