Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'-' value argument cannot be parsed #121

Closed
Byron opened this issue May 17, 2015 · 5 comments
Closed

'-' value argument cannot be parsed #121

Byron opened this issue May 17, 2015 · 5 comments
Assignees
Labels
C-bug Category: Updating dependencies

Comments

@Byron
Copy link
Contributor

Byron commented May 17, 2015

In an argument like the following:

Arg::with_name("foo")
                               .short("f")
                               .required(true)
                               .takes_value(true)

It seems impossible to provide a value that is or starts with a -. The latter is common to specify that input should be read from stdin, instead of from a file.

The actual output in my current (toy) program is:

$ trains -n -
The argument '--network <network>' requires a value but none was supplied

USAGE:
    trains --network <network>

For more information try --help
@kbknapp
Copy link
Member

kbknapp commented May 17, 2015

Ah ok, right now -- is special cased but - isn't, I just need to add it. I'm on mobile right now but its a trivial fix so I'll have it done tonight. Thanks!

@kbknapp kbknapp added the C-bug Category: Updating dependencies label May 17, 2015
@Byron
Copy link
Contributor Author

Byron commented May 17, 2015

Great to hear ! It would be great if you could publish that patch as well, so people building the tool tomorrow/early next week will have it. Thanks in advance.

The question i'd have is why '-' would need to be a special case. What I would expect is that if the argument takes any bounded amount of arguments, one would just pick them off the argument sequence without interpreting them at all. The only difficulty, as always, occurs if there are one or more arguments, which is when some special handling would be in order to prevent parsing subcommands as arguments for instance. It's just what came to my mind, I have no clue after all.

@kbknapp
Copy link
Member

kbknapp commented May 17, 2015

bc12e78 on master or v0.8.6 on crates.io fixes this ;)

The reason it's special cased is the way it decides when to stop parsing multiple arguments, so if you had a -f val val val -r other it stops parsing -f once it reaches a value starting with -, the problem was - alone starts with - :P But this is fixed now.

There are other ways to solve this, which I may look at in the future. The biggest issue is you can't just store the whole "flag" as the identifier, such as -f instead of simply f because short arguments can be combined such as -rfbZ is the same as -r -f -b -Z. I may look at this in the future, but it'd be a substantial change for an unknown gain - I'd have to test :)

@kbknapp kbknapp self-assigned this May 17, 2015
@kbknapp
Copy link
Member

kbknapp commented May 17, 2015

As a side note, this issue also helped something I'd totally forgotten about. - is used in some Unix/Linux utilities to denote "stdin" so not being able to parse - would have been a deal breaker ;) so, thanks again!

@Byron
Copy link
Contributor Author

Byron commented May 17, 2015

Yes, I see, there is more about argument parsing :) ! Totally forgot about the short flag concatenation.

Besides: You are welcome, it's always a pleasure to interact with this project !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants