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
Verify command line flags (by default) #3371
Comments
@sdarwin sounds like you want to make use of the https://docs.chocolatey.org/en-us/configuration#ignoreinvalidoptionsswitches This is enabled by default, since there are ways of using Chocolatey CLI where you specifically want to pass in options that Chocolatey CLI doesn't know about. However, for your use case, if you run:
You should get the result you want. Let me know if this answers your question, and we can close out this issue. |
Hi @gep13 , This was implemented in issue 586. Comments from there:
Well, if I run a powershell script it will give an error: script.ps1 -helpz
Usually if a new switch gets added in a future version, it becomes available in future versions. Older versions don't have access to that particular switch. But that is normal. What is the most frequent and common case of needing to pass unknown options to choco? If 97% of users are not applying unknown options flags, those users would be better off if the default setting was catching typos. Rather than allowing mistakes to go undetected. It would sort of make sense if this was the method to pass options directly to the underlying installer. However, to do that, you use |
One example would be the
Due to how Chocolatey CLI works, i.e. no phone home, or telemetry, we simply don't know what the usage is. If I have understood you correctly, what you are requesting is no longer that Chocolatey CLI detects that invalid options are passed in (since this functionality is already provided via the |
If "new" must be able to take arbitrary switches, then treat "new" differently. Allow that command to have unknown options. We can imagine, that most users are running "choco install", and most users don't know about the existence of "ignoreInvalidOptionsSwitches". Default settings should be aimed at the largest set of users, the typical user. There's a reason in Linux if you type
Error code 2. The problem with allowing unknown options is more than typos, it's also "misunderstandings". You construct a long, somewhat complicated installation command, believe it should be working, and there are no errors or warnings. Yet behind-the-scenes, it failed to do what you expected. While I believe the command should output an error message and exit with an error code, like
Perhaps implement the warning-only mode first and leave that in place for a couple years. Then eventually enable errors. A phased approach. If there is a case to be made for certain subcommands such as |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? |
The "default" behavior of a command line tool should be to verify the provided --option-flags. If 10% or fewer subcommands really do need to accept any input, it could be triggered by that particular subcommand itself. So let's say |
(emphasis mine). That hasn't been done, and that is why the issue was due to be closed. To set expectations, the default behaviour of this option is already established behaviour, and changing it would cause unexpected issues for some users. We would appreciate any feedback on how we highlight that this option being available, to more people. If I've misunderstood what you are asking, please let me know. |
I had already update the title, from "Verify command line flags" to -> "Verify command line flags (by default)". Now I have added text into the first post: "(the proposal is that this should occur 'by default'.) Implementing this feature request is more then toggling If there are currently any seldom-used, mysterious, but still necessary, switches that aren't documented, they should be added into the list of "valid command-line switches" in some way or another. But generally I suspect that 95% of users are running "choco install", and 95% of users don't know about Still the "average use case" would benefit from getting at least a warning when there's a problem with the command-line input. I had suggested a compromise. Instead of having |
As I mentioned above, the behaviour of Chocolatey CLI is already established, whether it's believed to right or wrong. So it's not something we'd be changing. Outside of making that change, I'm unclear what else needs to do be done here. |
In that case... How about a slightly different alternative then. Instead of modifying ignoreInvalidOptionsSwitches, add a new setting, something like "enable warnings". "enableWarningsInvalidOptionsSwitches". True by default. It will "show warnings when invalid options switches are found". at least in my opinion, since the warnings are sort of serious, they should be offset by surrounding spaces. Try to draw attention to them. |
Checklist
Is Your Feature Request Related To A Problem? Please describe.
It's easy to mistype any command. When that happens, it's helpful to get an informational error.
Here is an example:
Chocolatey doesn't indicate the option is invalid?
Or
Almost correct. The same problem. No warning message. No error message. Just a "success".
Describe The Solution. Why is it needed?
Sanitize command line flags. Return a clear error message "invalid option : X" . Exit with an error code.
It's better to return an error, than to allow the user to mistakenly believe they are getting certain options, but the options were misspelled.
(the proposal is that this should occur 'by default'.)
Additional Context
No response
Related Issues
No response
The text was updated successfully, but these errors were encountered: