What's the proper way to use std.getopt?

Jordi Gutiérrez Hermoso jordigh at octave.org
Mon Dec 11 23:42:01 UTC 2017


On Monday, 11 December 2017 at 21:24:41 UTC, Mike Wey wrote:

> try
> {
> 	auto helpInformation = getopt(
> 		args,
> 		"input|i", "The input", &input,
> 		"output|o", "The output", &output
> 	);
>
> 	if (helpInformation.helpWanted)
> 	{
> 		defaultGetoptPrinter("Description", helpInformation.options);
> 		exit(0);
> 	}
> }
> catch (GetOptException e)
> {
> 	writeln(e.msg);
> 	exit(1);
> }

But I would like to show the help docstring when processing the 
exception. It's pretty standard behaviour. If you give a program 
bad arguments, it just spits out a docstring of all options and 
what each does. Can this be achieved?




More information about the Digitalmars-d-learn mailing list