bigtiny has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm writing a script that will act as a partial wrapper for a source control system. That is, I want to write a script that will automate a few tasks in source control by calling the source control executable supplying some pertinent source control command options (based on context) and depending on those options, set others.

This tool is going to automate the act of creating a source repository which can be done in different contexts: init, clone, etc. Each of these requires a different set of options to the source control system executable, and I need to specify script specific options in addition. I hope this is clearer than mud =:-)

For example, a release engineer wants to clone a repository: The script will need to call the source control executable with the proper options for the cloning (and they can be different depending on exactly what the engineer wants to do), and then execute several steps that may involve other source control commands and more generalized actions to manage configuration etc.

I'm looking for strategies on how to handle the command line options for something like this. I've used getops::Long and am fairly comfortable with use it in a very basic way. In reading about it, it doesn't SEEM to have the capability to do what I need, but I may just be missing it. Anybody have any suggestions for strategies to handle something like this?

Thank you, Keith

Replies are listed 'Best First'.
Re: command line options and sub-options?
by SilasTheMonk (Chaplain) on Sep 23, 2010 at 19:53 UTC
    Have you looked at Getopt::Euclid? It gets the options from the pod and automatically gives you some help and version options.
Re: command line options and sub-options?
by JavaFan (Canon) on Sep 23, 2010 at 23:40 UTC
    One way of doing is it to make the wrapper script aware of all the possible options, read them in, deal with its own options, and pass the rest to whichever sub program it starts. Alternatively, require the wrapper options to be passed first, then the sub program options, separated by --. You can then use Getopt::Long in the wrapper program to read its own options; the rest of the options are available in @ARGV which can be passed to your sub program. A third option is to parse @ARGV yourself. It's not that complicated.