patch to use net options
hno at squid-cache.org
Tue May 24 21:04:40 GMT 2005
On Tue, 24 May 2005, [ISO-8859-1] LEOCADIE Grégory wrote:
> I'm ok with this way and it works,but it looks weird to have and to write a
> command like this: net -U toto%iscool share list -h 172.16.122.132
Perhaps -U should be a common option to rather than a global one..
allowing for syntaxes like
net share list -U toto%iscool -h 172.16.122.132
net share -h 172.16.122.132 list -U toto%iscool
(both works fine with the proper popt tables)
To realize this you need to divide options in three categories
a) Global options for the command as such.
b) Module specific options (tree hierarchy of modules possible)
c) Command specific options.
You could skip 'a' if you like. The only purpose of 'a' is to allow for
certain options before the sub-command name. Or alternatively you can make
the sub-commands include the global popt table allowing the user to
specify the global options anywhere he likes. Including the global popt
table is just a matter of adding an include to the sub-command popt
I have refined the example slightly based on your comments and some
further reading of popt.
* Found a somewhat undocumented popt support function quite handy for
sub-command processing: poptStrippedArgv(). Automatically preserves
argv and gives you argc making option processing in sub-commands
* Added a specialized help hook main, printing the available
* Made module2 dependent on module1, showing module inheritance.
* Added defines for including the options of a specific module similar
to the POPT_DEFAULT_HELP define provided by popt.
* Thanks to the defines consistent module help labels was added
explaining the grouping of the options to the user.
* Sub-commands now includes the global options in addition to the
options of the modules they depend on, allowing global options to be
placed anywhere on the command line (also included in sub-command help)
The example program demonstrating this use of popt can be found from
More information about the samba-technical