NAME main.rb SYNOPSIS a class factory and dsl for generating real main programs real quick URI http://rubyforge.org/projects/codeforpeople/ http://codeforpeople.com/lib/ruby/ INSTALL $sudo gem install main DESCRIPTION main.rb is a library which simplifies and unifies the details of creating command line programs. for instance, this program require 'main' Main { argument 'foo' option 'bar' def run p params['foo'] p params['bar'] exit_success! end } sets up a program which requires one argument, 'bar', and which may accept one command line switch, '--foo' in addition to the single option which is always accepted and handled appropriately: '--help', '-h'. for simple programs this is a real time saver but it's for more complex applications where main.rb's unification of parameter parsing, class configuration dsl, and auto-generation of usage messages can really streamline command line application development. for example the following 'a.rb' program: require 'main' Main { argument('foo'){ cast :int } keyword('bar'){ arity 2 cast :float defaults 0.0, 1.0 } option('foobar'){ argument :optional description 'the foobar option is very handy' } environment('BARFOO'){ cast :list_of_bool synopsis 'export barfoo=value' } def run p params['foo'].value p params['bar'].values p params['foobar'].value p params['BARFOO'].value end } when run with a command line of BARFOO=true,false,false ruby a.rb 42 bar=40 bar=2 --foobar=a will produce 42 [40.0, 2.0] "a" [true, false, false] while a command line of ruby a.rb --help will produce NAME a.rb SYNOPSIS a.rb foo [bar=bar] [options]+ PARAMETERS * foo [ 1 -> int(foo) ] * bar=bar [ 2 ~> float(bar=0.0,1.0) ] * --foobar=[foobar] [ 1 ~> foobar ] the foobar option is very handy