mitchellh / cli

A Go library for implementing command-line interfaces.
Mozilla Public License 2.0
1.73k stars 123 forks source link

Noop autocomplete setup if we're not autocompleting #82

Closed mitchellh closed 4 years ago

mitchellh commented 4 years ago

Setting up the autocomplete command requires initializing and walking through every subcommand in order to get their completion implementations. This means that if Autocomplete: true is on the CLI, every command is initialized on every single invocation.

This PR changes it so that we only initialize the autocompletion command if we detect that we're actually being invoked for autocompletion.

The practical impact is that if Autocomplete: true now and you're NOT actively autocompleting then we will only init and run the command that is requested. This is identical behavior to Autocomplete: false.

Luckily our tests already "black-box" (mostly) tested autocompletion so this change can verify that autocompletion still works.