Fix autocmpleting global flags

This PR vendors a change to the CLI package that allows autocompleting
global flags at the top level command.
This commit is contained in:
Alex Dadgar
2017-07-28 09:44:48 -07:00
parent 67705efb8f
commit fd06341d8d
3 changed files with 14 additions and 8 deletions

View File

@@ -153,6 +153,14 @@ func (c *CLI) IsVersion() bool {
func (c *CLI) Run() (int, error) {
c.once.Do(c.init)
// If this is a autocompletion request, satisfy it. This must be called
// first before anything else since its possible to be autocompleting
// -help or -version or other flags and we want to show completions
// and not actually write the help or version.
if c.Autocomplete && c.autocomplete.Complete() {
return 0, nil
}
// Just show the version and exit if instructed.
if c.IsVersion() && c.Version != "" {
c.HelpWriter.Write([]byte(c.Version + "\n"))
@@ -197,11 +205,6 @@ func (c *CLI) Run() (int, error) {
return 0, nil
}
// If this is a autocompletion request, satisfy it
if c.autocomplete.Complete() {
return 0, nil
}
}
// Attempt to get the factory function for creating the command