benjohn / fysh.org wrote:
> I've been writing a few unix scripts recently. I'm very much feeling the
> need for a framework that will let me build scripts and not worry about
> such common functionality as:
>
>   * providing parameters through the command line and config files, or
> falling back to program specified defaults.
>   * getting help on command usage (perhaps via embedded rdoc).
>
> I would imagine there is a developed framework out there to do this kind
> of thing?
>
> Cheers,
>   Benjohn

There are a number of alternative out there. A couple in particluar are
nice. Can't recall the name of it at the moment but one allows you to
define the syntax via USAGE docs and it will parse the docs to setup
the functionality for you. That's kind of cool, albeit not my style.
Anyone recall this lib?

Another way (my style) is Facets command.rb. It makes basic command
line scripts as easy as silly putty.

  require 'facet/command'

  class MyCommand << Console::Command

    # define some options

    def __help
      puts "HELP!"
      exit 0
    end

    def __debug
      $DEBUG = true
    end
    alias :_d :__debug

    def __file( name )
      @name = name
    end

    # define some subcommands

    def sub1
      puts "This is a subcommand for #{@name}"
    end

    def sub2( req )
      puts "This is a subcommand with a required parameter #{req}"
    end

  end

  MyCommand.execute

Running it:

  % mycmd --help
  HELP!

  % mycmd --file 'afile' sub1
  This is a subcommand for afile

&c.

It has some limitations in so far as sepcifying strict rules about
which subcommand and options work together but often that proves
unneccessary. Also, I haven't finished the automatic help system yet,
but I've started it and should be availbe soon.

Finally, yuo might be intersted in the project I'm working on right now
called, Script Sake (as in the drink). It's a build tool like Rake and
my clone of it, Reap, but it moves away from the monolithic "Rakefile"
idea and instead focuses on bolstering standard scripts. Should have a
realese ready shortly.

T.