std.getopt: checking if an option has been passed

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 7 04:40:53 PDT 2015


What's the best way to check if an (optional) argument has been 
passed?  One way is to use a default value, but I wonder if there 
is a tidier approach

Thanks.

(For startDate and endDate below)

struct NanoClientOptions
{
	string nanoUrl="tcp://127.0.0.1:9999";
	string[] tickers;
	DateTime startDate=DateTime(1,1,1);
	DateTime endDate=DateTime(9999,1,1);
}

auto helpInformation = getopt(
     args,
     "nanoUrl",  "Address of kaleidic data nanoserver eg 
tcp://127.0.0.1:9999",	&options.nanoUrl,
	    std.getopt.config.required,	"ticker|t", 	"Tickers to 
download data for",	&options.tickers,
	    "startDate|s", "Start Date",					&options.startDate,
	    "endDate|e", 	 "End Date",					&options.endDate
	    );

Laeeth


More information about the Digitalmars-d-learn mailing list