Skip to content

Commit

Permalink
Hide non-user commands from autocomplete output
Browse files Browse the repository at this point in the history
This PR hides non-user CLI commands from the list of autocomplete
suggestions.
  • Loading branch information
dadgar committed Sep 8, 2017
1 parent 4fb2dce commit ed8f07f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
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"}

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

0 comments on commit ed8f07f

Please sign in to comment.