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

Hide non-user commands from autocomplete output #3177

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ BUG FIXES:
* cli: Fix autocompletion of paths that include directories on zsh [GH-3129]
* cli: Fix job deployment -latest handling of jobs without deployments
[GH-3166]
* cli: Hide CLI commands not expected to be run by user from autocomplete
suggestions [GH-3177]
* cli: Status command honors exact job match even when it is the prefix of
another job [GH-3120]
* cli: Fix setting of TLSServerName for node API Client. This fixes an issue of
Expand Down
22 changes: 13 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,31 @@ func RunCustom(args []string, commands map[string]cli.CommandFactory) int {
commandsInclude := make([]string, 0, len(commands))
for k, _ := range commands {
switch k {
case "check":
case "deployment list", "deployment status", "deployment pause",
"deployment resume", "deployment fail", "deployment promote":
case "executor":
case "fs ls", "fs cat", "fs stat":
case "job deployments", "job dispatch", "job history", "job promote", "job revert":
case "namespace list", "namespace delete", "namespace apply":
case "operator raft", "operator raft list-peers", "operator raft remove-peer":
case "syslog":
default:
commandsInclude = append(commandsInclude, k)
}
}

// Hidden hides the commands from both help and autocomplete. Commands that
// users should not be running should be placed here, versus hiding
// subcommands from the main help, which should be filtered out of the
// commands above.
hidden := []string{"check", "executor", "syslog"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test to validate this.


cli := &cli.CLI{
Name: "nomad",
Version: version.GetVersion().FullVersionNumber(true),
Args: args,
Commands: commands,
Autocomplete: true,
HelpFunc: cli.FilteredHelpFunc(commandsInclude, helpFunc),
Name: "nomad",
Version: version.GetVersion().FullVersionNumber(true),
Args: args,
Commands: commands,
Autocomplete: true,
HiddenCommands: hidden,
HelpFunc: cli.FilteredHelpFunc(commandsInclude, helpFunc),
}

exitCode, err := cli.Run()
Expand Down
31 changes: 31 additions & 0 deletions vendor/github.com/mitchellh/cli/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1033,10 +1033,10 @@
"revision": "7e024ce8ce18b21b475ac6baf8fa3c42536bf2fa"
},
{
"checksumSHA1": "mjxSVrqngLZSyaQoEW2OLUb3oDs=",
"checksumSHA1": "UIqCj7qI0hhIMpAhS9YYqs2jD48=",
"path": "github.com/mitchellh/cli",
"revision": "7a1a617034de956eee640dfa5a7407ccc8c8d7e6",
"revisionTime": "2017-09-06T23:20:06Z"
"revision": "65fcae5817c8600da98ada9d7edf26dd1a84837b",
"revisionTime": "2017-09-08T18:10:43Z"
},
{
"checksumSHA1": "ttEN1Aupb7xpPMkQLqb3tzLFdXs=",
Expand Down