Add support for specifying only a shortflag#171
Add support for specifying only a shortflag#171cornfeedhobo wants to merge 4 commits intospf13:masterfrom
Conversation
|
I'm happy to have the option to have short flags without requiring long synonyms, but I would like boolean short flags to be handled more like non-boolean short flags for consistency. The current state where a flag with an argument is written There are 2 options that make sense to me and it would be reasonable to implement either or both: Option 1, allow the value to be specified as the next word, without an equals sign, just as with $ echo -b bold Option 2, allow negating a short option with a long option, so that boolean options can be set either way without an argument. Create a (possibly hidden) inverse long option using the $ echo -b bold The reason it is important to have a way of explicitly setting an option to its default value (e.g. BTW, this looks like this would also address spf13/cobra#918 |
|
@Nuru is this concern specific to my branch? Edit: I haven't looked at this in some time. I see what you mean. I'll think about it. |
@cornfeedhobo It is not entirely specific to your branch, but without a long name for the flag, this syntax I am complaining about is the only way left to override an option that defaults to |
|
Thinking more about it, I'm fully opposed to allowing short flags only. The only benefit to not having long options is slightly shorter help text. I think allowing short arguments without long arguments is problematic for a general utility such as this that goes into tools like cobra and viper which support multiple levels of configuration (config file, environment variables, command line), because the semantics (or at least the customary usage) of short flags is command-line only. Users wanting to override on the command line values specified elsewhere need to be able to set options back to defaults, and that is only customarily possible with long options. I'm tempted to write a new parsing library to implement options the way I think they should be, but I have other priorities at the moment. Meanwhile, you can see my suggestion for how to handle spf13/cobra#679 (comment) and #139 (comment) |
|
Haha, sounds like we'll have to agree to disagree. I will simply say that I think you are looking at this PR through your own narrow viewpoint, and that there are many valid reasons to support just short flags, especially since it's just another option, no in any way forced upon the user. |
|
@cornfeedhobo I'd love to hear some of your "many valid reasons" to deny users the option of using a long flag and associated long flag syntax. From my point of view, if you have a short option If you require short flags to also have long flags, then you can solve a lot of issues with consistency of syntax and ambiguity of parsing by limiting certain things to long flags. For example a boolean short flag |
No one is "deny"ing anything. This makes the flag library offer the same capability as the built-in flag library. Unfortunately, you're way too passionate to engage in this discussion further. It's out of the scope of my PR and it looks like you just want someone to argue with. Furthermore, this PR has been open for over a year and has no hope of being merged in sight and even if it is merged it has literally no affect on you. |
|
@therealmitchconnors any way to get some attention here? |
|
@spf13 looks like this issue has been open for a while. |
|
@cornfeedhobo Any chance you are interested in maintaining a fork with this patch in it? |
|
@xxxserxxx Yeah I'm considering it. I tried to discuss the issue over at spf13/cobra#1050, but as you can see, @jharshman completely shut down the conversation, and I'm kinda scared to push the issue now. This is the first time I've had to deal with censorship in opensource. I encourage you to push him on the matter. |
Yes that was the incorrect place to raise the issue.
I don't think you understand what censorship is. Since your comment on spf13/cobra#1050, I have obtained collaborator access to this repository with the intent of triaging open issues and Pull Requests. However, these things take time and other items have taken priority. Thank you for your patience. |
|
@jharshman Um, you chose to lock down an issue from comments when that isn't normal practice. That is literally censorship.
Cobra is tightly coupled to pflag - there is no interface allowing a drop in replacement for it. I don't know where else would have been a proper place to discuss forking and moving.
I think 2 years is extremely patient, and as you can see, I am not the first to discuss forking this project. In fact, most people I have discussed this with say that's what they do at their company. Alternatively, Cobra could remove this tight coupling and we wouldn't be having this issue. Either way, you've locked users into a rock and a hard place. I think my actions have been extremely polite considering the length of time, neglect, and importance of this library. |
jharshman
left a comment
There was a problem hiding this comment.
I don't think the implementation is quite there yet.
I'd rather this take the form of a new method(s) on FlagSet explicitly intended to use only short flags.
| if flag.Shorthand != "" && flag.ShorthandDeprecated == "" { | ||
| flagName = fmt.Sprintf("-%s, --%s", flag.Shorthand, flag.Name) | ||
| if flag.shorthandOnly { | ||
| flagName = fmt.Sprintf("-%s", flag.Shorthand) |
There was a problem hiding this comment.
This it technically just suppressing the long name for the flag.
Is there a setup where the flag only gets a shorthand? Something where you wouldn't have to explicitly specify "" for the flag name?
There was a problem hiding this comment.
Okay, I've started another branch that will take a more explicit approach. I'll post it soon, but it's a much larger diff.
|
@jharshman Please take a look at #256 and see if that is more suitable. |
|
Just use https://github.com/urfave/cli/ if you are starting out because this feature is not supported |
This PR seeks to add support for specifying flags with only a short flag. Tests have been adjusted and added, but suggestions for any additional validation are welcome.
Fixes #139
Closes #165
Fixes spf13/cobra#679