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

cmd/cue: fix help cmd incorrect behavior #2759

Closed
wants to merge 2 commits into from

Conversation

nnnkkk7
Copy link
Contributor

@nnnkkk7 nnnkkk7 commented Jan 6, 2024

This fixes the issue of incorrect behavior when requesting help for an unknown command in the CUE CLI.

  1. Modified the newHelpCmd function to handle unknown commands correctly.
  2. When an unknown cue help commands are entered, an error message is displayed and the program exits with a non-zero status code.
  3. This ensures that the CLI behaves as expected and provides useful feedback to the user when an unknown command is entered.

Fixes #2560

@nnnkkk7 nnnkkk7 requested a review from cueckoo as a code owner January 6, 2024 09:15
@mvdan
Copy link
Member

mvdan commented Jan 6, 2024

This would need a test; see the other cue help test scripts.

Also, I suspect this will break existing tests. Did you run them?

Copy link
Member

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the above

This fixes the issue of incorrect behavior when requesting help for an unknown command in the CUE CLI.
1. Modified the `newHelpCmd` function to handle unknown commands correctly.
2. When an unknown `cue help`  commands are entered, an error message is displayed and the program exits with a non-zero status code.
3. This ensures that the CLI behaves as expected and provides useful feedback to the user when an unknown command is entered.
Fixes cue-lang#2560

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
@nnnkkk7
Copy link
Contributor Author

nnnkkk7 commented Jan 8, 2024

thanks! i fixed it!

@mvdan
Copy link
Member

mvdan commented Jan 8, 2024

This would need a test; see the other cue help test scripts.

See the above - if you are fixing a bug, a test should be added. See https://github.com/cue-lang/cue/blob/master/CONTRIBUTING.md

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
@nnnkkk7
Copy link
Contributor Author

nnnkkk7 commented Jan 14, 2024

@mvdan
I missed it. Sorry, I added the test.
add test for os.Exit(1)

@mvdan
Copy link
Member

mvdan commented Mar 20, 2024

Thanks! No need to write a Go test and mock os.Exit for this; we already have integration tests for cmd/go at cmd/cue/cmd/testdata/script/help.txtar and sibling files like help_cmd.txtar, for example.

Also, is there a particular reason that you swapped Printf and CheckErr for PrintErrf and os.Exit? As far as I can tell, the fix here is the addition of || len(rests) != 0, so the other bits of the PR shouldn't be necessary.

cueckoo pushed a commit that referenced this pull request May 3, 2024
We cover all edge cases now; a missing help command, sub-command,
and "cmd" command, as well as all the valid help combinations.

Note that for unknown "cmd" commands we print a more precise error,
and we also check that custom commands are added to the help text
in all cases where we print help text for cmd.

We join help_hello.txtar with help_cmd.txtar given their overlap.

Thanks to Naoki Kuroda for proposing a version of the fix in #2759
which was adapted here, along with more testscript coverage.

Fixes #2560.
Fixes #2918.
Closes #2759 as partially merged.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I252e57c59eab499e40daea45355f1da75acba249
@mvdan
Copy link
Member

mvdan commented May 3, 2024

Did the above, as well as added more test cases, in this Gerrit patch: https://review.gerrithub.io/c/cue-lang/cue/+/1194247

Hope that's okay with you, and please let me know if you spot any issues there.

@cueckoo cueckoo closed this in 1be0b0f May 3, 2024
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

Successfully merging this pull request may close these issues.

cmd/cue: help cmd $cmd does not exit non-zero for unknown command
2 participants