getopt example please

Tobias Pankrath tobias at pankrath.net
Wed Feb 26 02:06:12 PST 2014


On Wednesday, 26 February 2014 at 09:57:19 UTC, Andrew Edwards 
wrote:
> Request a small example of how to use getopt to accomplish the 
> following:
>
> [1] program subcommand //process subcommand with default 
> arguments if any
> [2] program -h subcommand //output help information about 
> subcommand
> [3] program subcommand --option1 --option2 true option3=log.txt 
> // process subcommand with user specified options
>
> Thanks,
> Andrew

This is not fully automated with getopt. You could use getopt to 
parse all non-positional arguments and than parse the rest by 
hand.
--
getopt(args, ...);
--
Now, args[1] (or [0]?) should be "subcommand".


More information about the Digitalmars-d-learn mailing list