Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1178 (closed enhancement: wontfix)

Opened 16 years ago

Last modified 14 years ago

Arguments should support outputting parameters to certain types

Reported by: schveiguy Assigned to: kris
Priority: normal Milestone: 1.0
Component: Core Functionality Version: 0.99.6 Jeff
Keywords: Cc:

Description

One of the benefits of Phobos' std.getopt is it easily supports parsing integer arguments to integer variables. It would be cool if there were automatic built-in pieces that could be added as 'validators' that also save the argument to a variable.

For instance:

int timeout;
args.define("timeout").output(timeout);

This could be done using template member functions to determine the type. I think it could parse ints, longs, doubles, and strings with simple builtin functions (i.e. don't use Convert).

For anything other than those types, the default template could call a parse function on the given type, i.e.:

mytype var;
args.define("mytype").output(var);

and calling application with -mytype hello translates to calling var.parse("hello").

Then one could define wrapper structs that would do the translation on objects that don't have a built-in parse function, or for user-defined parsing (dates come to mind).

Change History

07/08/08 04:55:00 changed by kris

  • owner changed from sean to kris.
  • status changed from new to assigned.

as a general rule, we tend to avoid tight coupling where it doesn't add significant value. Hard to tell in this case, since it's almost trivial for one to import tango.util.Convert to do the appropriate work (as required) ?

11/09/09 04:45:24 changed by kris

  • status changed from assigned to closed.
  • resolution set to wontfix.

tango.text.Arguments support some rudimentary error testing, but we felt type-conversion should be external to it. There is support for a callback to be fired whenever an assignment is made to a defined argument, and this can be used to convert on the fly (and then call arg.fail appropriately)