From: ara.t.howard@... Date: 2007-03-21T04:56:24+09:00 Subject: Re: [ANN] main-0.0.1 - command line apps for the truly lazy On Wed, 21 Mar 2007, Justin Bailey wrote: > On 3/20/07, Ara.T.Howard wrote: >> >> >> NAME >> main.rb >> >> SYNOPSIS >> a class factory and dsl for generating real main programs real quick > > > Excellent looking library. I have some fascination with writing CLI apps, > and have used the commandline gem extensively. My one complaint with that > library was the obscure syntax used for parsing command line options. > > Can the options parsed be used outside the Main { } declaration? For small > scripts, the "run" method is fine, but for larger apps it becomes necessary > to break things up. Specifically, I am thinking of some highline driven apps > I have which would benefit from the option parsing provided here. harp:~ > cat a.rb require 'rubygems' require 'main' ARGV.replace %w( --foo=42 42.0 ) main = Main.new{ option('foo='){ cast :int } option('bar='){ cast :float } } p main.param['foo'] p main.param['bar'] harp:~ > ruby a.rb # # i realize, as i post this, that i'd meant for one to be able to say argv = %w( --foo=42 42.0 ) env = {'PATH' => '/usr/loca/bin'} main = Main.new(argv, env){ option('foo='){ cast :int } option('bar='){ cast :float } } but neglected to pass some information through. i'll think about it and ensure that's possible v.s directly manipulating ARGV this is quite a re-work of what's in alib, so i'm all ears for comments/feature-requests. btw. the usage can be overridden simply with Main{ usage 'my usage string' } regards. -a -- be kind whenever possible... it is always possible. - the dalai lama