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

Configure tango.text.Arguments

Moderators: larsivi kris

Posted: 08/08/11 11:23:31

I want the arguments parser to only care about the arguments I specify and then let everything else pass through. Example:

auto args = new Arguments;
args['a'];

args.parse("-a=1 -b=2 foo");
assert(args[null].assigned == ["-b=2", "foo"]);

Is this possible?

Author Message

Posted: 08/09/11 17:36:06

anything preceded with an argument-flag will be considered fair-game for testing. If configured to support anonymous arguments, these will be accepted without further testing. However, once anonymous is disabled it is off for all arguments. In short: it doesn't support some arguments as anonymous and others not.

One workaround might be to use a different flag-character (perhaps '/') for the optional ones? Those would then wind up in the default arg list

Posted: 08/12/11 12:15:19

I'm not quite sure what you mean with "anonymous arguments".

Posted: 08/12/11 18:35:59

'anonymous' == 'sloppy' :: processing of arguments which are not explicitly defined to the parser.

http://www.dsource.org/projects/tango/browser/trunk/tango/text/Arguments.d

Posted: 08/13/11 11:20:18

What do you think about adding an option that will, when enabled, let every argument that is not specified pass through? Could a patch for that be accepted ?

Posted: 08/13/11 12:18:44

Note that the "standard" way to do this is to specify something like a "--" switch, and everything that follows it is fair game. Putting anonymous in between can be problematic in several manners.

Posted: 08/14/11 15:56:31

I may just tell what I'm doing and someone might have a better suggestion. I'm working on a command line based tool that accepts various arguments, it also accept various actions/commands. In addition to that the actions can accept various arguments, i.e.

tool -v action -p

So I was planning to use one instance of Arguments for handling the global arguments for the tool. Then each action would have an associated instance of Arguments for handling its own arguments. The global Arguments instance should just care about the pre defined arguments for that particular instance and let everything else pass through to the Arguments instance for the give action.

So I thought it would just be easiest to do a simple modification to Arguments that passes through every argument that hasn't previously been specified.

Posted: 08/14/11 16:01:47

larsivi wrote:

Note that the "standard" way to do this is to specify something like a "--" switch, and everything that follows it is fair game. Putting anonymous in between can be problematic in several manners.

If I take my example above, you mean I should do something like this:

tool -v -- action -p

If that's the case, I would rather not have add those extra dashes.