diff --git a/cmd/cue/cmd/help.go b/cmd/cue/cmd/help.go index 7156724347f..bf77410d19d 100644 --- a/cmd/cue/cmd/help.go +++ b/cmd/cue/cmd/help.go @@ -58,10 +58,12 @@ func newHelpCmd(c *Command) *cobra.Command { // ["cmd", "mycmd"] // ["cmd", "mycmd", "./mypkg"] // - // We want to skip the first two arguments in pkgArgs. - pkgArgs := args[1:] - if len(pkgArgs) > 0 { - pkgArgs = pkgArgs[1:] + // In the third case, we want to load ["./mypkg"] + // and we want to look up the help for ["cmd", "mycmd"]. + var pkgArgs []string + if len(args) > 2 { + pkgArgs = args[2:] + args = args[:2] } tools, err := buildTools(c, pkgArgs) diff --git a/cmd/cue/cmd/testdata/script/help_cmd.txtar b/cmd/cue/cmd/testdata/script/help_cmd.txtar index 4a4e96ead39..df43f549a48 100644 --- a/cmd/cue/cmd/testdata/script/help_cmd.txtar +++ b/cmd/cue/cmd/testdata/script/help_cmd.txtar @@ -8,6 +8,14 @@ cmp stdout cue-help-cmd.stdout exec cue help cmd hello cmp stdout cue-help-cmd-hello.stdout +exec cue help cmd hello . +cmp stdout cue-help-cmd-hello.stdout + +mkdir subdir +cp task_tool.cue subdir +exec cue help cmd hello ./subdir +cmp stdout cue-help-cmd-hello.stdout + ! exec cue help cmd missing stderr -count=1 'Unknown cmd command: missing' stderr -count=1 '^Available Commands:$'