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

Support space as the delimiter for long arguments #17

Closed
josegonzalez opened this issue Mar 16, 2015 · 4 comments
Closed

Support space as the delimiter for long arguments #17

josegonzalez opened this issue Mar 16, 2015 · 4 comments

Comments

@josegonzalez
Copy link

Most cli tools I use have a space character to delimit the flag and it's option, and it would be cool to be able to do so for pflag. I realize this would be yet another departure from the flag stdlib, but it would definitely be cool to have.

I tried just changing https://github.com/ogier/pflag/blob/master/flag.go#L429 to a space character, but it seems I'll also need to change something in FlagSet, just not sure where. Would be happy to make a PR adding another method that configures this and make the requisite changes given some direction :)

@ogier
Copy link
Owner

ogier commented Mar 17, 2015

I'm worried that this will make boolean arguments ambiguous. For example, does the following set the bar flag to false, or does it set the bar flag to true with one positional argument?

foo --bar false

Also #16 is a request to make arguments for any long argument optional, which I think makes sense, but would make parsing any long flag without an = ambiguous.

In the end, the main spec pflag follows when deciding how to parse flags is http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html which doesn't allow long options without an = sign.

@ogier ogier closed this as completed Mar 17, 2015
@ncw
Copy link

ncw commented Jun 25, 2015

Actually flag does allow long options with a space. Here is an example on the playground.

The standard GNU getopt_long also accepts --flag argument, try this for an example

ls --sort extension

The docs you linked to above is the document for getopt_long - it may be that the = convention is a POSIX thing only.

The flag package ignores arguments for bool options. Here is a demo on the playground, so --bar is the same as -bar=true and -bar true just treats true as another argument.

So I think it would be more standards compliant (both with flag and getopt_long) to make pflag allow space as the delimiter with long arguments.

PS thanks for a great package - I'm using it in rclone.

@josegonzalez
Copy link
Author

Looks like this is implemented in the spf13 fork. I switched to that for now.

@ncw
Copy link

ncw commented Aug 28, 2015

@josegonzalez thanks for the heads up - I'm going to investigate.

ThinkChaos pushed a commit to ThinkChaos/pflag that referenced this issue Feb 28, 2022
Add docs and examples how to use the flag normalization func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants