On Wed, Jul 31, 2002 at 02:47:17PM +0900, Patrick Bennett wrote:
> Jim Freeze wrote:
> 
> To be specific, this is a wrapper script for perforce.  Perforce has a 
> command-line program called 'p4' that takes a command followed by 
> multiple arguments (as well as some 'global' arguments).
> I need to handle perforce native commands by passing through 
> commands/arguments onto the regular p4 command (where appropriate).
> I also need to handle my 'extended' commands that have been created for 
> our users.   These commands act just like the regular p4 commands, so
> p dircheck -a -e -c -d --log
> would go through several layers
> one would need to pick off the --log (a global option) so that 
> diagnostic logging could be enabled.
> the rest (in this case) would be handled by the dircheck method which 
> would pull off the -a -e -c options.
> 
> >In all of my usage, I collect all the arguments up front.
> >So, for the above I would do:
> >
> If I did that, then I'd end up with an unmaintainable mess 
> unfortunately.  Each 'command' may be a relatively complex set of 
> actions with its own completely independent set of options.
> -c for one command might not take any arguments.  For another it might 
>  >require< an argument.  Specifying them all in one place isn't feasible.

Hmm, I would not consider many of the options very pretty.
If you know the possible arguments that is good. If you 
know what parameters they take, that is even better.
In such a case, you can go ahead and tell the wrapper about
these arguments.
If you don't know the number of arguments, then you could
list the options as having optional arguments.

Then, in  the sample I gave earlier, I added the following:

  not_handled = []
    opts.each do |opt, arg|
      case opt
        ## We handle log
        when "--log"
          puts "parsing: #{opt}: #{arg}"
        ## We pass cc
        else
          ## Unknown option  (probably need some error checking here)
          not_handled << [opt, arg]
      end#case
    end#each

When your done, add the not_handled array back to ARGV

 ARGV.unshift(not_handled).flatten!

-- 
Jim Freeze
If only I had something clever to say for my comment...
~