www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.getopt: checking if an option has been passed

reply "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
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
Aug 07 2015
parent "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Friday, 7 August 2015 at 11:40:54 UTC, Laeeth Isharc wrote:
 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
I guess answer is simple: std.getopt doesn't handle DateTimes, so I have to use a callback, in which case I can just track whether it's been passed myself.
Aug 07 2015