D Configuration Framework (alias Program Options)

Bill Baxter dnewsgroup at billbaxter.com
Tue Oct 9 19:20:38 PDT 2007


Marcin Kuszczak wrote:
> import doost.util.config.ProgramOptions;
> import doost.util.config.CommandLineStorage;
> 
> void main(char[][] args) {
>   //Definition of simplest options stack
>   auto po = (new ProgramOptions)
>                 .next(
>             (new CommandLineStorage(args))
>                 .caption("Command line options")
>                 .options()
>                   ("help,h", "produce help message")
>                   ("compression", define!(int), "set compression level")
>                   ("sync", "stores cmdline options in persistent backend")
>                   ()
>             );
> 
>   //Conecting to storages
>   po.connect();
> 
>   //Reading options
>   if ("help" in po) writefln(po);
>   if ("compression" in po)      
>         writefln("Compresson level set to: ", po["compression"].as!(uint));
> 
>   //Disconnecting storages
>   po.disconnect;
> }

Nice updates.  The example above doesn't work for me.  I get a runtime 
error to the tune of
"""
Error: AssertError Failure 
f:/usr/pkg/d/dsss/bin\..\include\d\doost\core\Any.d(121) Error: type of 
value (int) is different than requested (uint).
"""


But it does seem to work if I change the define!(int) to define!(uint).

Also on the web page it said po[["compression"]].  But I went ahead and 
fixed that since it's a wiki. :-) 
[http://www.dsource.org/projects/doost/wiki/ProgramOptions]

I didn't fix the int/uint thing on the wiki page because it seems that's 
maybe something you think should work?

--bb



More information about the Digitalmars-d-announce mailing list