Add support for specifying only a shortflag#256
Add support for specifying only a shortflag#256cornfeedhobo wants to merge 2 commits intospf13:masterfrom
Conversation
|
@cornfeedhobo yes I like this approach. 👍 |
|
Not my project (so not my call to make), but I think that mixing "only short flag" and "short or long flags" is an inconsistent approach to UX; doubly so since the convention around short flags is that any values passed to them are space delimited and and long flags can be space or I know some projects do it ( |
|
For anyone following this. I'm still working on it, but haven't had time to write all the tests I want. |
56fd8a5 to
4dee4e4
Compare
4dee4e4 to
42ad93d
Compare
|
@jharshman I started adding tests but that is becoming sprawling. I'm submitting this in it's current state. Let me know what you think. |
|
Just tried this out, looks pretty good to me. |
|
This has been merged into my fork. Closing now. |
|
why does this feature which support shorthand only flags not work now. How to use this feature? |
|
it is not merged into spf13/pflag. You need to use his fork if that is an option for you: go mod edit -replace github.com/spf13/pflag=github.com/cornfeedhobo/pflag
`` |
|
I have read some of threads/PR's regarding short-only flags, and I have to say, I am fundamentally disappointed in how this feature has progressed; or failed to progress in the end. The lack of response and gaslighting that happened against the original contributor is fundamentally shocking:
At the end of the day, short-only and long-only flags are not only common place, but in many applications they are required; particularly GNU and POSIX applications. Anyone arguing against short-only options are explicitly dictating the development direction of other projects as well as basically telling anyone that needs short-only options to go-somewhere-else. I have such a project, and at this point, I will be going somewhere else. PS: I would like to have added this comment to the related Cobra discussion, but that discussion was locked, even though I very much feel it shouldn't have been. Refs: |
|
@major0 , unfortunately I haven't been active on this project for some time due to conflicting priorities. I don't remember locking that conversation but I agree that it shouldn't have been. I'll leave it to active maintainers to unlock that discussion as I don't want to step on anyone's toes. I reviewed the PRs and conversations and I do wish I had more time to dedicate to this back then. I think short-only flags are a perfectly reasonable feature to have and I regret any mishandling of the subject. |
|
What I currently find the most ironic about this is that, in the
Anything which supports POSIX
_ Note: With some fairly minor processing, it is also possible to pause processing the args list when encountering a subcmd, process subcmd flags, and then return to processing parentCmd flags. But I totally understand how no one wants to support subcmd's overriding global flags, even if it seems sort of lazy when one encounters a system that doesn't allow it._ Now, I have a pretty common POSIX/GNU scenario that requires a many-to-one mapping of multiple short-flags to a single long-flag. This behavior is common in CLI's which support options such as E.g. Or we can pull from a real POSIX/GNU tool, And the format can also be selected via:
This is typically implemented by either:
Something like: // example from how I would like to see this in Cobra
cmd.Flags().DestVarP(&format, "", "x", "across", "list entries by lines instead of columns")Where we can disable long options by passing Also, this should not support
Similar requirements arise with In the scope of POSIX/GNU commands, a "toggled" command needs to support knowing what the Honestly, w/out the above functionality, I would suggest removing any claim about spf13/pflag as being POSIX/GNU. Simply supporting long-opts and short-opts does not POSIX/GNU one make. It is a little like claiming all vehicles with 4 wheels that are painted red and have a gasoline engine can claim to be "Porsche Like"... |
|
I'm sure there are differing opinions on this topic but I think the first implementation example you gave makes a lot of sense to me. |
|
I just came on here as a co-maintainer to help unblock things late last year; most of the referred background is completely unknown to me (and, to be frank, does not appear from your description to have been constructive enough that it's worth digging deeply into...). Is there something we co-maintainers can do today to try to rectify this? Are there any PRs or issues you would like to see (re-)considered? (This one?) If a PR is re-opened against latest |
Add docs/upstream-issues.md mapping OptArgs features to open issues and rejected PRs in upstream projects: - Boolean negation (--no-flag): spf13/pflag#214, spf13/cobra#958, spf13/cobra#1821 - Boolean prefix pairs: spf13/pflag#214 - Short-only flags: spf13/pflag#139, spf13/pflag#256 - Subcommand help inheritance: alexflint/go-arg#101 - BoolArgValuer: spf13/pflag#214 Add upstream issue references to expected_diffs.go in both pflags and goarg compat modules.
Link OptArgs-exclusive features to the upstream issues they address: pflags: - Boolean negation: spf13/pflag#214, spf13/cobra#958 - Short-only flags: spf13/pflag#139, spf13/pflag#256 - BoolArgValuer: spf13/pflag#214 goarg: - Parent flag inheritance: alexflint/go-arg#101
This PR seeks to add support for specifying flags with only a shortflag.
Fixes #139
Closes #165
Closes #171
Fixes spf13/cobra#679