this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: forbid `cue help help` in favor of `cue help`

Requesting the help text for the help command itself is a bit silly.
`cue help` already describes how to query help for commands or topics.
Fail even though "help" is a valid command, just a special one.

This means that the help command no longer needs a long help text.
While here, slightly expand its short help text to clarify
that it also covers additional help topics beyond commands.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9f8541133981a7c7c3838f1783e9c89dbbe0bbcb
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195931
Reviewed-by: Jonathan Matthews <github@hello.jonathanmatthews.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+22 -4
+5 -3
cmd/cue/cmd/help.go
··· 37 37 func newHelpCmd(c *Command) *cobra.Command { 38 38 cmd := &cobra.Command{ 39 39 Use: "help [command]", 40 - Short: "Help about any command", 41 - Long: `Help provides help for any command in the application. 42 - Simply type ` + c.Name() + ` help [path to command] for full details.`, 40 + Short: "show help text for a command or topic", 43 41 Run: func(_ *cobra.Command, args []string) { 44 42 findCmd := func() (*cobra.Command, bool) { 45 43 cmd, rest, err := c.Root().Find(args) ··· 47 45 return cmd, found 48 46 } 49 47 cmd, found := findCmd() 48 + // Treat `cue help help` as an unknown help topic; just use `cue help`. 49 + if found && cmd.Name() == "help" { 50 + cmd, found = nil, false 51 + } 50 52 isCmd := len(args) > 0 && args[0] == "cmd" 51 53 if isCmd { 52 54 // args is one of:
+10
cmd/cue/cmd/root.go
··· 177 177 cmd := &cobra.Command{ 178 178 Use: "cue", 179 179 Short: "cue emits configuration files to user-defined commands.", 180 + // TODO(mvdan): the text below should not jump straight into `cue cmd`, 181 + // and instead give a high level overview of CUE and its commands. 182 + // TODO(mvdan): cobra's help text template ends with 183 + // Use "cue [command] --help" for more information about a command. 184 + // which isn't great; use our own template to say 185 + // Use "cue help [command]" for more information about a command. 186 + // TODO(mvdan): cobra's help text template suggests help topics 187 + // such as `cue inputs`; swap with `cue help inputs`. 180 188 Long: `cue evaluates CUE files, an extension of JSON, and sends them 181 189 to user-defined commands for processing. 182 190 ··· 256 264 cmd.Flag("help").Hidden = true 257 265 258 266 // "help" is treated as a special command by cobra. 267 + // TODO(mvdan): hide this command; `cue help` showing itself in the list of commands 268 + // is not particularly helpful, and we already mention it as the way to get help. 259 269 cmd.SetHelpCommand(newHelpCmd(c)) 260 270 261 271 // For `cue mycmd` to be a shortcut for `cue cmd mycmd`.
+7 -1
cmd/cue/cmd/testdata/script/help.txtar
··· 48 48 stderr -count=1 'Unknown help topic: mod missing' 49 49 stderr -count=1 '^Available Commands:$' 50 50 51 + # Requesting the help text for the help command itself is a bit silly. 52 + # `cue help` already describes how to query help for commands or topics. 53 + # Fail even though technically "help" is a valid command, just a special one. 54 + ! exec cue help help 55 + stderr -count=1 'Unknown help topic: help' 56 + 51 57 -- stdout.golden -- 52 58 cue evaluates CUE files, an extension of JSON, and sends them 53 59 to user-defined commands for processing. ··· 81 87 fix rewrite packages to latest standards 82 88 fmt formats CUE configuration files 83 89 get add dependencies to the current module 84 - help Help about any command 90 + help show help text for a command or topic 85 91 import convert other formats to CUE files 86 92 login log into a CUE registry 87 93 mod module maintenance