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: help cmd $cmd does not exit non-zero for unknown command #2560

Closed
myitcv opened this issue Aug 22, 2023 · 0 comments
Closed

cmd/cue: help cmd $cmd does not exit non-zero for unknown command #2560

myitcv opened this issue Aug 22, 2023 · 0 comments
Labels

Comments

@myitcv
Copy link
Member

myitcv commented Aug 22, 2023

What version of CUE are you using (cue version)?

$ cue version
cue version v0.0.0-20230821113919-220b44e973ef

go version go1.20.6
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
             vcs git
    vcs.revision 220b44e973eff9d41f2067499f20a12b6a0a6f29
        vcs.time 2023-08-21T11:39:19Z
    vcs.modified false

Does this issue reproduce with the latest release?

Yes

What did you do?

exec cue help cmd x
stdout 'long desc'

! exec cue help cmd doesnotexist
stderr 'unknown command .* doesnotexist'

-- x_tool.cue --
package x

import "tool/cli"

command: x: cli.Print & {
	$long: "long desc"
	text: "test"
}

What did you expect to see?

Passing test (modulo the correct expectation on stderr)

What did you see instead?

# known command (0.016s)
# unknown command (0.012s)
> ! exec cue help cmd doesnotexist
[stdout]
cmd executes the named command for each of the named instances.

...

Run "cue help commands" for more details on tasks and commands.

Usage:
  cue cmd <name> [inputs] [flags]
  cue cmd [command]

Available Commands:
  x

Flags:
  -t, --inject stringArray   set the value of a tagged field
  -T, --inject-vars          inject system variables in tags (default true)

Global Flags:
  -E, --all-errors   print all available errors
  -i, --ignore       proceed in the presence of errors
  -s, --simplify     simplify output
      --strict       report errors for lossy mappings
      --trace        trace computation
  -v, --verbose      print information about progress

Use "cue cmd [command] --help" for more information about a command.
FAIL: /tmp/testscript1425870910/repro.txtar/script.txtar:6: unexpected command success

i.e. the requesting for help for an unknown command resulted in a zero exit code.

@myitcv myitcv added this to the Needs planning milestone Aug 22, 2023
@mvdan mvdan added the good first issue Good for newcomers label Oct 21, 2023
nnnkkk7 added a commit to nnnkkk7/cue that referenced this issue Jan 6, 2024
This fixes the issue of incorrect behavior when requesting help for an unknown command in the CUE CLI.
1. Modified the  function to handle unknown commands correctly.
2. When an unknown  and  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>
nnnkkk7 added a commit to nnnkkk7/cue that referenced this issue Jan 8, 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 cue-lang#2560

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

Signed-off-by: nnnkkk7 <kurodanaoki0711pana@gmail.com>
cueckoo pushed a commit that referenced this issue 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
@cueckoo cueckoo closed this as completed in 1be0b0f May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants