Skip to content

Commit 222b689

Browse files
committed
cmd/cue: fix cue help cmd mycmd ./mypkg
Jonathan Matthews correctly pointed out that a tutorial used the command successfully up to and including CUE v0.8.0, but it broke from v0.9.0. My refactor at https://cuelang.org/cl/1194247 was overall good, but it did break this edge case, which in my defense had no tests. Add tests, and fix the code. The issue was that we left args as ["cmd", "mycmd", "./mypkg"], where the valid command is only ["cmd", "mycmd"], so we treated this scenario as an unknown subcommand. Fixes #3462. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I2208fa8411f1122ede863b8dc6a5d81805562f30 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201709 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 842fa25 commit 222b689

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

cmd/cue/cmd/help.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ func newHelpCmd(c *Command) *cobra.Command {
5858
// ["cmd", "mycmd"]
5959
// ["cmd", "mycmd", "./mypkg"]
6060
//
61-
// We want to skip the first two arguments in pkgArgs.
62-
pkgArgs := args[1:]
63-
if len(pkgArgs) > 0 {
64-
pkgArgs = pkgArgs[1:]
61+
// In the third case, we want to load ["./mypkg"]
62+
// and we want to look up the help for ["cmd", "mycmd"].
63+
var pkgArgs []string
64+
if len(args) > 2 {
65+
pkgArgs = args[2:]
66+
args = args[:2]
6567
}
6668

6769
tools, err := buildTools(c, pkgArgs)

cmd/cue/cmd/testdata/script/help_cmd.txtar

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ cmp stdout cue-help-cmd.stdout
88
exec cue help cmd hello
99
cmp stdout cue-help-cmd-hello.stdout
1010

11+
exec cue help cmd hello .
12+
cmp stdout cue-help-cmd-hello.stdout
13+
14+
mkdir subdir
15+
cp task_tool.cue subdir
16+
exec cue help cmd hello ./subdir
17+
cmp stdout cue-help-cmd-hello.stdout
18+
1119
! exec cue help cmd missing
1220
stderr -count=1 'Unknown cmd command: missing'
1321
stderr -count=1 '^Available Commands:$'

0 commit comments

Comments
 (0)