[#281559] NTLM authentication with httpclient — Jim Clark <diegoslice@...>

I have rewritten my net/http script that I had questions on a couple of

11 messages 2007/12/01

[#281591] question about iterator — Paul Private <paulus4605@...>

dear

15 messages 2007/12/01

[#281603] Identifying a volume as being an iPod — John Joyce <dangerwillrobinsondanger@...>

Does anybody know how to identify a mounted volume as being an iPod ?

21 messages 2007/12/01

[#281612] Why are "Array#push" and "pop" not "push!" and "pop!"? — samppi <rbysamppi@...>

As a novice in Ruby, I love its elegance and consistence; it's now one

30 messages 2007/12/01

[#281653] irb and unix shells — Robert Jones <robertjones21@...>

Can you use irb in place of shells like bash or rc?

21 messages 2007/12/02

[#281779] What are the differences between c++ and Ruby? — "duddilla's" <radhika.duddilla@...>

Hi

13 messages 2007/12/03

[#281810] Everyone's favorite flow control: retry — Charles Oliver Nutter <charles.nutter@...>

Today I was thinking about retry support in JRuby, and figured we've

18 messages 2007/12/03

[#281917] What is the best way to interact with a JDBC database — Venks <venkatesh.mantha@...>

Hi,

14 messages 2007/12/03

[#281965] Rubyisms wanted to shorten code in search program — RichardOnRails <RichardDummyMailbox58407@...>

Hi,

10 messages 2007/12/04

[#282099] Re: Ruby App Distribution — Joe L <superist_joe@...>

I don't see how RubyScript2Exe would work when it's a virtual machine. Would it package the entire virtual machine inside the exe?

12 messages 2007/12/04
[#282102] Re: Ruby App Distribution — "Adam Shelly" <adam.shelly@...> 2007/12/04

On 12/4/07, Joe L <superist_joe@yahoo.com> wrote:

[#282100] I consider this a bug in Ruby... — "Just Another Victim of the Ambient Morality" <ihatespam@...>

I would like to know why the following code doesn't work:

14 messages 2007/12/04

[#282123] Ruby works but not JRuby - when using MySQL Driver — Venks <venkatesh.mantha@...>

Here is the simple Ruby program that works with "Ruby" but gives an

10 messages 2007/12/05

[#282276] Worth an RCR? static_type_check, polymorphic_type_check, quacks_like — John Carter <john.carter@...>

Is there another library like this? I would love it if it were just

17 messages 2007/12/05

[#282277] Capturing STDOUT from a system call (POSIX) into an array — Venks <venkatesh.mantha@...>

What's the best way to capture STDOUT into an Array? I looked at

12 messages 2007/12/05

[#282340] if /hello/ =~line — Peter Loftus <loftuz@...>

Got help with this code earlier its just checking a file for a line

12 messages 2007/12/06

[#282373] function like "function_exits" — Girard Fred <fred.girard@...>

Hi all,

14 messages 2007/12/06

[#282374] regular expression. newbie problem. — Johnathan Smith <stu_09@...>

Hi,

15 messages 2007/12/06
[#282378] Re: regular expression. newbie problem. — Reacher <brandon.g.jones@...> 2007/12/06

On Dec 6, 9:42 am, Johnathan Smith <stu...@hotmail.com> wrote:

[#282413] array iterator that have more arrays that also need iteratio — Raimon Fs <coder@...>

Hello ...

14 messages 2007/12/06
[#282415] Re: array iterator that have more arrays that also need iteratio — Xavier Noria <fxn@...> 2007/12/06

On Dec 6, 2007, at 8:25 PM, Raimon Fs wrote:

[#282447] search-0.0.1 — "ara.t.howard" <ara.t.howard@...>

14 messages 2007/12/06

[#282501] Dynamic local vars — Vasyl Smirnov <vasyl.smirnov@...>

Hi,

14 messages 2007/12/07

[#282605] Word Loop (#149) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

49 messages 2007/12/07

[#282633] Problem with Hash of Arrays — Jimi Damon <jdamon@...>

I am new to Ruby , but I consider this feature to be a bug.

15 messages 2007/12/07

[#282673] ruby certification — dare ruby <martin@...>

Dear friends,

41 messages 2007/12/08
[#282695] Re: ruby certification — "Austin Ziegler" <halostatue@...> 2007/12/08

On 12/8/07, dare ruby <martin@angleritech.com> wrote:

[#282696] Re: ruby certification — John Joyce <dangerwillrobinsondanger@...> 2007/12/08

Oh, come on.

[#282703] Re: ruby certification — Gregory Seidman <gsslist+ruby@...> 2007/12/08

On Sat, Dec 08, 2007 at 11:25:59PM +0900, John Joyce wrote:

[#282762] Re: ruby certification — Jim Clark <diegoslice@...> 2007/12/09

Gregory Seidman wrote:

[#282779] Re: ruby certification — "Austin Ziegler" <halostatue@...> 2007/12/09

On 12/9/07, Jim Clark <diegoslice@gmail.com> wrote:

[#282942] Re: ruby certification — Jim Clark <diegoslice@...> 2007/12/10

Austin Ziegler wrote:

[#282962] Re: ruby certification — "Todd Benson" <caduceass@...> 2007/12/10

On Dec 10, 2007 12:28 PM, Jim Clark <diegoslice@gmail.com> wrote:

[#282971] Re: ruby certification — "Austin Ziegler" <halostatue@...> 2007/12/10

On 12/10/07, Todd Benson <caduceass@gmail.com> wrote:

[#282684] Looking for a new web framework. — "Tim Uckun" <timuckun@...>

I am looking for a web framework designed to handle multiple domains

16 messages 2007/12/08
[#282752] Re: Looking for a new web framework. — "Mikel Lindsaar" <raasdnil@...> 2007/12/09

Go get Mephisto and put it on rails. Can handle multiple domains, with

[#282748] How much would variable declarations in Ruby make you wince? — "Just Another Victim of the Ambient Morality" <ihatespam@...>

So, I had a conversation with a colleague of mine and he brought up a

60 messages 2007/12/09

[#282822] Confirm My Ruby/GUI investigation? — Wesley Rishel <wes.rishel@...>

I have been reviewing the copious old threads (and the various cited web

14 messages 2007/12/09

[#282995] REXml help - Insert newlines into large xml file — Sean Nakasone <seannakasone@...>

Hello, I have a large xml file that does not have any newlines in it. Can

10 messages 2007/12/11

[#283063] While statements in ruby — Mark Mr <pimea.mark@...>

Hi guys, I have a probably simple question. I dont know how to do

13 messages 2007/12/11

[#283079] opposite .nil? — "Andrew Stone" <stonelists@...>

I've looked around, but could not find a method that is the opposite of

16 messages 2007/12/11

[#283128] How To Avoid Ugly Declerations — Michael Boutros <me@...>

Hello! More and more I find myself having to do something like this:

13 messages 2007/12/12

[#283243] Connecting to Outlook 'Saved Items' folder using win32ole — Alex DeCaria <alex.decaria@...>

Can anyone tell me how to connect to the 'Saved Items' folder in Outlook

11 messages 2007/12/12

[#283396] Showing Running Processes in variable — jackster the jackle <contact@...>

I want to capture the list of running processes on my computer. I am to

13 messages 2007/12/13

[#283432] Newbie Question: What is a class for? — Matthias Borgeson <hibridmatthais@...>

Hello all-

11 messages 2007/12/13

[#283446] Third edition of "Programming Ruby" now in beta — Dave Thomas <dave@...>

Ruby 1.9 is just around the corner, so it looks like a good time to

10 messages 2007/12/13

[#283530] Programmer Ping-Pong (#150) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

43 messages 2007/12/14
[#283538] Re: [QUIZ] Programmer Ping-Pong (#150) — Paul Irofti <bulibuta@...> 2007/12/14

On 2007-12-14, Ruby Quiz <james@grayproductions.net> wrote:

[#283545] Good Ruby IDE for Debian Linux? — "Steckly, Ron" <rsteckly@...>

Hi all,

19 messages 2007/12/14

[#283574] simple way to turn "foo and bar" to "+foo +bar" — Max Williams <toastkid.williams@...>

I want to add a slightly hacky feature into my boolean mysql search

11 messages 2007/12/14

[#283673] Smallest device to code ruby on? — Casimir P <pikselNOSPAMMi@...>

Whats the smallest gadget you can code (and compile) ruby on?

25 messages 2007/12/15

[#283708] autoindenting ruby — "Martin DeMello" <martindemello@...>

Something most of the "IDE roundup" threads seem to pass over lightly

12 messages 2007/12/15

[#283753] Backslashes in Command Line Arguments — Joseph Pecoraro <joepeck02@...>

In writing a script that takes strings on the command line I have run

13 messages 2007/12/16

[#283811] teams -> members -> users — John Griffiths <indiehead@...>

trying to work this out, giving me a headache,

11 messages 2007/12/16

[#283870] Is there any way to pass further the "hidden" block? — "Chiyuan Zhang" <pluskid@...>

Like this:

13 messages 2007/12/17

[#283917] dividing by two and rounding up — Tom Norian <tomnorian@...>

Hey all...I am hoping for a tip

16 messages 2007/12/17

[#283970] Best compiled language for extending Ruby — Sharkie Landshark <shark.fin.soup@...>

I want to write my core logics in a compiled language for 1) performance

26 messages 2007/12/18

[#284001] String#[] behaviour — DNNX <6aLLIaPuMoB@...>

'asd'[0...10] returns 'asd' while 'asd'[-10..-1] returns nil.

14 messages 2007/12/18

[#284037] New to ruby — bigbrother <Cowboyninja@...>

Hey guys, I'm pretty new to ruby. I've got a question

15 messages 2007/12/18

[#284038] Check if directory exists — Florian Schaf <flo.schaf@...>

hi!

13 messages 2007/12/18

[#284082] Hpricot syntax different from Xpath ? — Celine <xhanrot@...>

Hi all

14 messages 2007/12/18

[#284215] best way to distribute? — Pavel Pvl <pavel989@...>

hi, what is the best way to distribute ruby apps without having the end

23 messages 2007/12/19

[#284268] RubyGems 1.0.0 — Eric Hodel <drbrain@...7.net>

Release 1.0.0 fixes several bugs.

24 messages 2007/12/20
[#284328] Re: [ANN] RubyGems 1.0.0 — Jim Morris <ml@...4net.com> 2007/12/20

After trying to install both from the source and from gem update --system

[#284363] RubyGems 1.0.1 — Eric Hodel <drbrain@...7.net>

= Announce: RubyGems Release 1.0.1

12 messages 2007/12/21

[#284462] Matz says namespaces are too hard to implement - why? — Stefan Rusterholz <apeiros@...>

Short primer: What are namespaces?

40 messages 2007/12/22
[#284478] Re: Matz says namespaces are too hard to implement - why? — Robert Klemme <shortcutter@...> 2007/12/22

On 22.12.2007 04:18, Stefan Rusterholz wrote:

[#284479] Re: Matz says namespaces are too hard to implement - why? — Charles Oliver Nutter <charles.nutter@...> 2007/12/22

Robert Klemme wrote:

[#284486] Re: Matz says namespaces are too hard to implement - why? — Stefan Rusterholz <apeiros@...> 2007/12/22

> Or perhaps, the various implementers will be able to answer this

[#284488] Re: Matz says namespaces are too hard to implement - why? — Charles Oliver Nutter <charles.nutter@...> 2007/12/22

Stefan Rusterholz wrote:

[#284491] Re: Matz says namespaces are too hard to implement - why? — Stefan Rusterholz <apeiros@...> 2007/12/22

Charles Oliver Nutter wrote:

[#284493] Re: Matz says namespaces are too hard to implement - why? — Charles Oliver Nutter <charles.nutter@...> 2007/12/22

Stefan Rusterholz wrote:

[#284494] Re: Matz says namespaces are too hard to implement - why? — Stefan Rusterholz <apeiros@...> 2007/12/22

Charles Oliver Nutter wrote:

[#285031] Re: Matz says namespaces are too hard to implement - why? — "Eivind Eklund" <eeklund@...> 2007/12/27

On Dec 22, 2007 4:22 PM, Charles Oliver Nutter <charles.nutter@sun.com> wrote:

[#285115] Re: Matz says namespaces are too hard to implement - why? — Charles Oliver Nutter <charles.nutter@...> 2007/12/28

Eivind Eklund wrote:

[#284644] C++ Functors and Ruby extensions — "Jason Roelofs" <jameskilton@...>

I wonder if anyone has tried to do what I'm doing and if they've come up

10 messages 2007/12/24

[#284651] Trouble with Readline and Building Ruby 1.9 — "James Herdman" <james.herdman@...>

I'm having a little trouble building Ruby 1.9. I'm building on

14 messages 2007/12/24

[#284720] Ruby 1.9.0 is released — Yukihiro Matsumoto <matz@...>

Hi,

54 messages 2007/12/25
[#284729] Re: Ruby 1.9.0 is released — Rk Ch <rollingwoods@...> 2007/12/25

Great christmas gift! Thanks for guys hard worked.

[#284786] Re: Ruby 1.9.0 is released — Yukihiro Matsumoto <matz@...> 2007/12/26

Hi,

[#284800] Re: Ruby 1.9.0 is released — "Jeremy McAnally" <jeremymcanally@...> 2007/12/26

Could you point out some areas that are in dire need of documentation?

[#284731] OT: Polyglot programming article? — Jay Levitt <jay+news@...>

About three or four months ago, I ran across a great article/blog post

10 messages 2007/12/25

[#284772] qt4 bindings, threads — "daniel 虧erud" <daniel.akerud@...>

I couldn't find a mailinglist for the Qt4 Ruby bindings, so I try here. It

11 messages 2007/12/25

[#284867] Destroying an Object — Ken Awamura <ken.awamura@...>

Suppose I create a new object:

19 messages 2007/12/26

[#284894] Purpose of Ruby 1.9? — "=?ISO-8859-2?Q?Rados=B3aw_Bu=B3at?=" <radek.bulat@...>

First of all I want to thank Matz and Ko1 for yours great work! I

26 messages 2007/12/26
[#284896] Re: Purpose of Ruby 1.9? — "Luiz Vitor Martinez Cardoso" <grabber@...> 2007/12/26

You are asking very usefull questions! Well... we need wait to someone

[#284905] Re: Purpose of Ruby 1.9? — "Windham, Kristopher R." <kriswindham@...> 2007/12/26

in the Desktop reference by Matz, printed in 2002,

[#284906] Re: Purpose of Ruby 1.9? — "Rick DeNatale" <rick.denatale@...> 2007/12/26

On Dec 26, 2007 5:39 PM, Windham, Kristopher R. <kriswindham@gmail.com> wrote:

[#284918] convert excel spreadsheet to csv — Junkone <junkone1@...>

is there any library to convert excel file to csv.

12 messages 2007/12/27

[#284923] Re: using reg expr with array.index — MonkeeSage <MonkeeSage@...>

On Dec 26, 4:32 pm, Esmail <ebonak_de...@hotmail.com> wrote:

12 messages 2007/12/27

[#284960] Add Array#first= and Array#last= to std lib — "Robert Klemme" <shortcutter@...>

Hi,

35 messages 2007/12/27

[#284980] about method docs — Santanu <thisissantanu@...>

Hello Everybody,

16 messages 2007/12/27

[#285003] Port Ruby on Rails Application — Snoop1990 Snoop1990 <snoopy1990@...>

Hello,

15 messages 2007/12/27

[#285118] testing for 64-bit environment — Tom Metge <tom@...>

subject says it all- anyone know a way to determine if the host system

12 messages 2007/12/28

[#285223] How to jump over the first line in a file? (newbie) — Mark Toth <mark.toth@...>

I have this code:

14 messages 2007/12/28

[#285294] Using "sort!" in a C extension (1.9 problem) — Andre Nathan <andre@...>

Hello

23 messages 2007/12/29
[#285349] Re: Using "sort!" in a C extension (1.9 problem) — "KUBO Takehiro" <kubo@...> 2007/12/30

Hi,

[#285300] Mr Bones - 1.1.0 — "Tim Pease" <tim.pease@...>

Bones

17 messages 2007/12/29

[#285315] Can Ruby be a keylogger on Win/Mac? — Jay Levitt <jay+news@...>

I know the subject's vague; that's because I don't know what I'm talking

14 messages 2007/12/29

[#285475] Best way to download >1GB files — thefed <fedzor@...>

What is the best way to download files from the internet (HTTP) that

19 messages 2007/12/31

[ANN] main-2.6.0

From: "ara.t.howard" <ara.t.howard@...>
Date: 2007-12-06 16:47:44 UTC
List: ruby-talk #282399

NAME
   main.rb

SYNOPSIS
   a class factory and dsl for generating command line programs real  
quick

URI
   http://codeforpeople.com/lib/ruby/
   http://rubyforge.org/projects/codeforpeople/
   http://codeforpeople.rubyforge.org/svn/

INSTALL
   gem install main

HISTORY
   2.6.0
     - added 'mixin' feaature for storing, and later evaluating a  
block of
       code.  the purpose of this is for use with modes where you  
want to keep
       your code dry, but may not want to define something in the  
base class
       for all to inherit.  'mixin' allows you to define the code to  
inherit
       once and the selectively drop it in child classes (modes) on  
demand.
       for example

         Main {
           mixin :foobar do
             option 'foo'
             option 'bar'
           end

           mode :install do
             mixin :foobar
           end

           mode :uninstall do
             mixin :foobar
           end

           mode :clean do
           end
         }

     - mode definitions are now deferred to the end of the Main  
block, so you
       can do this

         Main {
           mode 'a' do
             mixin :foo
           end

           mode 'b' do
             mixin :foo
           end

           def inherited_method
             42
           end

           mixin 'foo' do
             def another_inherited_method
               'forty-two'
             end
           end
         }

     - added sanity check at end of paramter contruction

     - improved auto usage generation when arity is used with arguments

     - removed 'p' shortcut in paramerter dsl because it collided with
       Kernel.p.  it's now called 'param'.  this method is availble  
*inside* a
       parameter definition

         option('foo', 'f'){
           synopsis "arity = #{ param.arity }"
         }

     - fixed bug where '--' did not signal the end of parameter  
parsing in a
       getoptlong compliant way

     - added (before/after)_parse_parameters, (before/after) 
_initialize, and
       (before/after)_run hooks

     - fixed bug where adding to usage via

         usage['my_section'] = 'custom message'

       totally horked the default auto generated usage message

     - updated dependancies in gemspec.rb for attributes (~> 5.0.0) and
       arrayfields (~> 4.3.0)

     - check that client code defined run, iff not wrap_run! is  
called.  this is
       so mains with a mode, but no run defined, still function  
correctly when
       passed a mode

     - added new shortcut for creating accessors for parameters.  for  
example

         option('foo'){
           argument :required
           cast :int
           attr
         }

         def run
           p foo ### this attr will return the parameter's *value*
         end

       a block can be passed to specify how to extract the value from  
the
       parameter

         argument('foo'){
           optional
           default 21
           cast :int
           attr{|param| param.value * 2}
         }

         def run
           p foo #=> 42
         end

     - fixed bug where 'abort("message")' would print "message" twice  
on exit
       if running under a nested mode (yes again - the fix in 2.4.0  
wasn't
       complete)

     - added a time cast, which uses Time.parse

         argument('login_time'){ cast :time }

     - added a date cast, which uses Date.parse

         argument('login_date'){ cast :date }


DESCRIPTION
   main.rb features the following:

     - unification of option, argument, keyword, and environment  
parameter
       parsing
     - auto generation of usage and help messages
     - support for mode/sub-commands
     - io redirection support
     - logging hooks using ruby's built-in logging mechanism
     - intelligent error handling and exit codes
     - use as dsl or library for building Main objects
     - parsing user defined ARGV and ENV
     - zero requirements for understanding the obtuse apis of *any*  
command
       line option parsers
     - leather pants

   in short main.rb aims to drastically lower the barrier to writing  
uniform
   command line applications.

   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/mode  
which is always
   accepted and handled appropriately: 'help', '--help', '-h'.  for  
the most
   part main.rb stays out of your command line namespace but insists  
that your
   application has at least a help mode/option.

   main.rb supports sub-commands in a very simple way

     require 'main'

     Main {
       mode 'install' do
         def run() puts 'installing...' end
       end

       mode 'uninstall' do
         def run() puts 'uninstalling...' end
       end
     }

   which allows a program, called 'a.rb', to be invoked as

     ruby a.rb install

   and

     ruby a.rb uninstall

   for simple programs main.rb 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

       * --help, -h

       * export barfoo=value

   and this shows how all of argument, keyword, option, and  
environment parsing
   can be declartively dealt with in a unified fashion - the dsl for all
   parameter types is the same - and how auto synopsis and usage  
generation saves
   keystrokes.  the parameter synopsis is compact and can be read as

       * foo [ 1 -> int(foo) ]

         'one argument will get processed via int(argument_name)'

           1        : one argument
           ->       : will get processed (the argument is required)
           int(foo) : the cast is int, the arg name is foo

       * bar=bar [ 2 ~> float(bar=0.0,1.0) ]

         'two keyword arguments might be processed via float 
(bar=0.0,1.0)'

           2                  : two arguments
           ~>                 : might be processed (the argument is  
optional)
           float(bar=0.0,1.0) : the cast will be float, the default  
values are
                                0.0 and 1.0

       * --foobar=[foobar] [ 1 ~> foobar ]

         'one option with optional argument may be given directly'

       * --help, -h

         no synopsis, simple switch takes no args and is not required

       * export barfoo=value

         a user defined synopsis

SAMPLES

   <========< samples/a.rb >========>

   ~ > cat samples/a.rb

     require 'main'

     ARGV.replace %w( 42 ) if ARGV.empty?

     Main {
       argument('foo'){
         required                    # this is the default
         cast :int                   # value cast to Fixnum
         validate{|foo| foo == 42}   # raises error in failure case
         description 'the foo param' # shown in --help
       }

       def run
         p params['foo'].given?
         p params['foo'].value
       end
     }

   ~ > ruby samples/a.rb

     true
     42

   ~ > ruby samples/a.rb --help

     NAME
       a.rb

     SYNOPSIS
       a.rb foo [options]+

     PARAMETERS
       foo (1 -> int(foo))
           the foo param
       --help, -h



   <========< samples/b.rb >========>

   ~ > cat samples/b.rb

     require 'main'

     ARGV.replace %w( 40 1 1 ) if ARGV.empty?

     Main {
       argument('foo'){
         arity 3                             # foo will given three  
times
         cast :int                           # value cast to Fixnum
         validate{|foo| [40,1].include? foo} # raises error in  
failure case
         description 'the foo param'         # shown in --help
       }

       def run
         p params['foo'].given?
         p params['foo'].values
       end
     }

   ~ > ruby samples/b.rb

     true
     [40, 1, 1]

   ~ > ruby samples/b.rb --help

     NAME
       b.rb

     SYNOPSIS
       b.rb foo foo foo [options]+

     PARAMETERS
       foo (3 -> int(foo))
           the foo param
       --help, -h



   <========< samples/c.rb >========>

   ~ > cat samples/c.rb

     require 'main'

     ARGV.replace %w( foo=40 foo=2 bar=false ) if ARGV.empty?

     Main {
       keyword('foo'){
         required  # by default keywords are not required
         arity 2
         cast :float
       }
       keyword('bar'){
         cast :bool
       }

       def run
         p params['foo'].given?
         p params['foo'].values
         p params['bar'].given?
         p params['bar'].value
       end
     }

   ~ > ruby samples/c.rb

     true
     [40.0, 2.0]
     true
     false

   ~ > ruby samples/c.rb --help

     NAME
       c.rb

     SYNOPSIS
       c.rb foo=foo [bar=bar] [options]+

     PARAMETERS
       foo=foo (2 -> float(foo))
       bar=bar (1 ~> bool(bar))
       --help, -h



   <========< samples/d.rb >========>

   ~ > cat samples/d.rb

     require 'main'

     ARGV.replace %w( --foo=40 -f2 ) if ARGV.empty?

     Main {
       option('foo', 'f'){
         required  # by default options are not required, we could  
use 'foo=foo'
                   # above as a shortcut
         argument_required
         arity 2
         cast :float
       }

       option('bar=[bar]', 'b'){  # note shortcut syntax for optional  
args
         # argument_optional      # we could also use this method
         cast :bool
         default false
       }

       def run
         p params['foo'].given?
         p params['foo'].values
         p params['bar'].given?
         p params['bar'].value
       end
     }

   ~ > ruby samples/d.rb

     true
     [40.0, 2.0]
     nil
     false

   ~ > ruby samples/d.rb --help

     NAME
       d.rb

     SYNOPSIS
       d.rb --foo=foo [options]+

     PARAMETERS
       --foo=foo, -f (2 -> float(foo))
       --bar=[bar], -b (0 ~> bool(bar=false))
       --help, -h



DOCS
   test/main.rb

   find ./lib |xargs vim -o

API

   Main {

    
######################################################################## 
###
   #                       CLASS LEVEL  
API                                   #
    
######################################################################## 
###
   #
   # the name of the program, auto-set and used in usage
   #
     program 'foo.rb'
   #
   # a short description of program functionality, auto-set and used  
in usage
   #
     synopsis "foo.rb arg [options]+"
   #
   # long description of program functionality, used in usage iff set
   #
     description <<-hdoc
       this text will automatically be indented to the right level.

       it should describe how the program works in detail
     hdoc
   #
   # used in usage iff set
   #
     author 'ara.t.howard@gmail.com'
   #
   # used in usage
   #
     version '0.0.42'
   #
   # stdin/out/err can be anthing which responds to read/write or a  
string
   # which will be opened as in the appropriate mode
   #
     stdin '/dev/null'
     stdout '/dev/null'
     stderr open('/dev/null', 'w')
   #
   # the logger should be a Logger object, something 'write'-able, or  
a string
   # which will be used to open the logger.  the logger_level  
specifies the
   # initalize verbosity setting, the default is Logger::INFO
   #
     logger(( program + '.log' ))
     logger_level Logger::DEBUG
   #
   # you can configure exit codes.  the defaults are shown
   #
     exit_success # 0
     exit_failure # 1
     exit_warn    # 42
   #
   # the usage object is rather complex.  by default it's an object  
which can
   # be built up in sections using the
   #
   #   usage["BUGS"] = "something about bugs'
   #
   # syntax to append sections onto the already pre-built usage  
message which
   # contains program, synopsis, parameter descriptions and the like
   #
   # however, you always replace the usage object wholesale with one  
of your
   # chosing like so
   #
     usage <<-txt
       my own usage message
     txt

    
######################################################################## 
###
   #                         MODE  
API                                        #
    
######################################################################## 
###
   #
   # modes are class factories that inherit from their parent class.   
they can
   # be nested *arbitrarily* deep.  usage messages are tailored for  
each mode.
   # modes are, for the most part, independant classes but parameters  
are
   # always a superset of the parent class - a mode accepts all of  
it's parents
   # paramters *plus* and additional ones
   #
     option 'inherited-option'
     argument 'inherited-argument'

     mode 'install' do
       option 'force' do
         description 'clobber existing installation'
       end

       def run
         inherited_method()
         puts 'installing...'
       end

       mode 'docs' do
         description 'installs the docs'

         def run
           puts 'installing docs...'
         end
       end
     end

     mode 'un-install' do
       option 'force' do
         description 'remove even if dependancies exist'
       end

       def run
         inherited_method()
         puts 'un-installing...'
       end
     end

     def run
       puts 'no mode yo?'
     end

     def inherited_method
       puts 'superclass_method...'
     end


    
######################################################################## 
###
   #                         PARAMETER  
API                                   #
    
######################################################################## 
###
   #
   # all the parameter types of argument|keyword|option|environment  
share this
   # api.  you must specify the type when the parameter method is used.
   # alternatively used one of the shortcut methods
   # argument|keyword|option|environment.  in otherwords
   #
   #   parameter('foo'){ type :option }
   #
   # is synonymous with
   #
   #   option('foo'){ }
   #
     option 'foo' {
     #
     # required - whether this paramter must by supplied on the  
command line.
     # note that you can create 'required' options with this keyword
     #
       required # or required true
     #
     # argument_required - applies only to options.
     #
       argument_required # argument :required
     #
     # argument_optional - applies only to options.
     #
       argument_optional # argument :optional
     #
     # cast - should be either a lambda taking one argument, or a symbol
     # designation one of the built in casts defined in Main::Cast.   
supported
     # types are :boolean|:integer|:float|:numeric|:string|:uri.   
built-in
     # casts can be abbreviated
     #
       cast :int
     #
     # validate - should be a lambda taking one argument and returning
     # true|false
     #
       validate{|int| int == 42}
     #
     # synopsis - should be a concise characterization of the  
paramter.  a
     # default synopsis is built automatically from the parameter.  this
     # information is displayed in the usage message
     #
       synopsis '--foo'
     #
     # description - a longer description of the paramter.  it  
appears in the
     # usage also.
     #
       description 'a long description of foo'
     #
     # arity - indicates how many times the parameter should appear  
on the
     # command line.  the default is one.  negative arities are  
supported and
     # follow the same rules as ruby methods/procs.
     #
       arity 2
     #
     # default - you can provide a default value in case none is  
given.  the
     # alias 'defaults' reads a bit nicer when you are giving a list of
     # defaults for paramters of > 1 arity
     #
       defaults 40, 2
     #
     # you can add custom per-parameter error handlers using the  
following
     #
       error :before do
         puts 'this fires *before* normal error handling using  
#instance_eval...'
       end

       error do
         puts 'this fires *instead of* normal error handling using  
#instance_eval...'
       end

       error :after do
         puts 'this fires *after* normal error handling using  
#instance_eval...'
       end
     }

    
######################################################################## 
###
   #                       INSTANCE LEVEL  
API                                #
    
######################################################################## 
###
   #
   # you must define a run method.  it is the only method you must  
define.
   #
     def run
       #
       # all parameters are available in the 'params' hash and via  
the alias
       # 'param'.  it can be indexed via string or symbol.  the  
values are all
       # Main::Parameter objects
       #
         foo = params['foo']
       #
       # the given? method indicates whether or not the parameter was  
given on
       # the commandline/environment, etc.  in particular this will  
not be true
       # when a default value was specified but no parameter was given
       #
         foo.given?
       #
       # the list of all values can be retrieved via 'values'.  note  
that this
       # is always an array.
       #
         p foo.values
       #
       # the __first__ value can be retrieved via 'value'.  note that  
this
       # never an array.
       #
         p foo.value
       #
       # the methods debug|info|warn|error|fatal are delegated to the  
logger
       # object
       #
         info{ "this goes to the log" }
       #
       # you can set the exit_status at anytime.  this status is used  
when
       # exiting the program.  exceptions cause this to be  
ext_failure if, and
       # only if, the current value was exit_success.  in otherwords an
       # un-caught exception always results in a failing exit_status
       #
         exit_status exit_failure
       #
       # a few shortcuts both set the exit_status and exit the program.
       #
         exit_success!
         exit_failure!
         exit_warn!
     end

   }


a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama




In This Thread

Prev Next