-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: refactor help texts and topics
Because additional help topics used to be non-runnable commands hanging from the root `cue` command, they used to behave in rather odd ways. For example, even though we often suggested using them via `cue help filetypes`, they still worked as `cue filetypes` or `cue filetypes --help` for no good reason. Hang the non-runnable commands from the `cue help` subcommand, meaning that `cue filetypes` is now treated as an unknown command. This seems better for the user experience too; for example, if a user tried to tab-complete `cue fi`, we should only suggest `cue fix` and not `cue filetypes`. Because help topics now hang as subcommands from `cue help`, spf13/cobra's default help template would no longer show them in the help text for the root command. Start using our own template, as a simplified and tweaked version of the default template, which resolves this issue. Our own template also tweaks a few other sharp edges while here: * Do not show global flags in `cue help`; they take up space, and they aren't useful unless a user is running a subcommand. Subcommand help texts already list the same global flags. * Suggest `cue help [command]` rather than `cue [command] --help`, which reads better and is shorter to type, and is also consistent with additional help topics such as `cue help filetypes`. * Hide `cue help` from the available commands list; we already suggest it as the way to get help texts, so we don't need to show it twice in the top-level help text. This is a precursor to removing support for `cue foo` as a short-hand for `cue cmd foo`, as some of the logic to handle these extra root-level commands is shared. For #2519. Signed-off-by: Daniel Martí <mvdan@mvdan.cc> Change-Id: I76d0c687e88bc3f237d952a98b4578516f36c5c0 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199622 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Matthew Sackman <matthew@cue.works>
- Loading branch information
Showing
5 changed files
with
120 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
! exec cue unknown | ||
! stdout . | ||
cmp stderr unknown_cmd.out | ||
|
||
! exec cue --unknown | ||
! stdout . | ||
cmp stderr unknown_flag.out | ||
|
||
-- unknown_cmd.out -- | ||
no commands defined | ||
Ensure custom commands are defined in a "_tool.cue" file. | ||
Run 'cue help cmd' to list available custom commands. | ||
Run 'cue help' to see the built-in 'cue' commands. | ||
-- unknown_flag.out -- | ||
unknown flag: --unknown |