FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using positional arguments

 
Post new topic   Reply to topic     Forum Index -> Doost
View previous topic :: View next topic  
Author Message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Tue Oct 09, 2007 11:41 pm    Post subject: Using positional arguments Reply with quote

I'm having trouble understanding how to use positional arguments.

This seems to work:
Code:

    auto po = (new ProgramOptions)
      .next(
            (new CommandLineStorage(args))
            .caption("Command line options:")
            .options()
            ("help,h", "produce help message")
            ("outdir", define!(string), "set directory for generated output files")
            ("shapes", define!(string[]).composing, "shape input files names (2)")
            ("shapes=2", new PositionalOption)
            ("sync", "stores cmdline options in persistent backend")
            ("selfname", new SelfName)
            ()
              );


However, in the help message there's the cryptic line "shapes=2 interpretation of position's meaning for unmatched option". And it has both that and "--shapes arg" implying that there's only one --shapes argument.

Also the syntax "shapes=2" seems a little odd. It looks like you're setting shapes to be #2 rather than saying there are two positional arguments that take this value. Maybe "shapes[2]" would be a better way to express that. It would also be nice to be able to specify that exactly 2 are required, or <=2, or >2 etc. You can check it yourself, but if ProgramOptions doesn't know what you want then it can't generate a reasonable help message.
Back to top
View user's profile Send private message
aarti_pl



Joined: 25 Jul 2006
Posts: 28

PostPosted: Fri Oct 12, 2007 3:40 am    Post subject: Reply with quote

Quote:

However, in the help message there's the cryptic line "shapes=2 interpretation of position's meaning for unmatched option". And it has both that and "--shapes arg" implying that there's only one --shapes argument.


Message for positional option is just a default one. You can set your own in positional option definition:
e.g. ("shapes=2", "your description", new PositionalOption)

But of course default description probably is not best. Better suggestion is welcomed Laughing

The second form is because you still can use it in a following way:

--shapes=circle,triangle,square

and it will work as expected.

Quote:

Also the syntax "shapes=2" seems a little odd. It looks like you're setting shapes to be #2 rather than saying there are two positional arguments that take this value. Maybe "shapes[2]" would be a better way to express that.


It was easy to parse, but yes, I think that there might be a better way to express this. I don't like very much '[2]' syntax.

Maybe it would be better to have:
("2*shapes, 3*names, path", "your description", new PositionalOption)
?

Quote:

It would also be nice to be able to specify that exactly 2 are required, or <=2, or >2 etc. You can check it yourself, but if ProgramOptions doesn't know what you want then it can't generate a reasonable help message.


Probably something like this:
("2*shapes[r], 3*names, 1*path[r], path", "your description", new PositionalOption)

Uff... it's getting complicated... Maybe it will be too complicated and gain will be not that big? I will think about it some more...
Back to top
View user's profile Send private message
baxissimo



Joined: 23 Oct 2006
Posts: 241
Location: Tokyo, Japan

PostPosted: Fri Oct 12, 2007 5:57 am    Post subject: Reply with quote

Some regexp's have syntax for matching between n and m arguments. I think it's like "foobar{m,n}" means takes between m and n matches.

Here's python's regexp syntax: http://docs.python.org/lib/re-syntax.html

Oh D's regexps have that syntax too:
http://www.digitalmars.com/ctg/regular.html

--bb
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Doost All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group