docs: document bash completion in README
Also, change command `golangci-lint completion` to `golangci-lint completion bash`.
This commit is contained in:
parent
91e90eba6b
commit
5fb91e6434
30
README.md
30
README.md
@ -19,6 +19,7 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
|
|||||||
* [Trusted By](#trusted-by)
|
* [Trusted By](#trusted-by)
|
||||||
* [Quick Start](#quick-start)
|
* [Quick Start](#quick-start)
|
||||||
* [Editor Integration](#editor-integration)
|
* [Editor Integration](#editor-integration)
|
||||||
|
* [Shell Completion](#shell-completion)
|
||||||
* [Comparison](#comparison)
|
* [Comparison](#comparison)
|
||||||
* [Performance](#performance)
|
* [Performance](#performance)
|
||||||
* [Internals](#internals)
|
* [Internals](#internals)
|
||||||
@ -250,6 +251,35 @@ golangci-lint run --disable-all -E errcheck
|
|||||||
* ale [merged pull request](https://github.com/w0rp/ale/pull/1890) with golangci-lint support
|
* ale [merged pull request](https://github.com/w0rp/ale/pull/1890) with golangci-lint support
|
||||||
6. Atom - [go-plus](https://atom.io/packages/go-plus) supports golangci-lint.
|
6. Atom - [go-plus](https://atom.io/packages/go-plus) supports golangci-lint.
|
||||||
|
|
||||||
|
## Shell Completion
|
||||||
|
|
||||||
|
`golangci-lint` can generate bash completion file.
|
||||||
|
|
||||||
|
### Mac OS X
|
||||||
|
|
||||||
|
Yhere are two versions of `bash-completion`, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The `golangci-lint` completion script doesn’t work correctly with bash-completion v1 and Bash 3.2. It requires bash-completion v2 and Bash 4.1+. Thus, to be able to correctly use `golangci-lint` completion on macOS, you have to install and use Bash 4.1+ ([instructions](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer).
|
||||||
|
|
||||||
|
Install `bash-completion v2`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install bash-completion@2
|
||||||
|
echo 'export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"' >>~/.bashrc
|
||||||
|
echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >>~/.bashrc
|
||||||
|
exec bash # reload and replace (if it was updated) shell
|
||||||
|
type _init_completion && echo "completion is OK" # verify that bash-completion v2 is correctly installed
|
||||||
|
```
|
||||||
|
|
||||||
|
Add `golangci-lint` bash completion:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo 'source <(golangci-lint completion bash)' >>~/.bashrc
|
||||||
|
source ~/.bashrc
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
|
||||||
|
See [kubectl instructions](https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion) and don't forget to replace `kubectl` with `golangci-lint`.
|
||||||
|
|
||||||
## Comparison
|
## Comparison
|
||||||
|
|
||||||
### `golangci-lint` vs `gometalinter`
|
### `golangci-lint` vs `gometalinter`
|
||||||
|
@ -19,6 +19,7 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
|
|||||||
* [Trusted By](#trusted-by)
|
* [Trusted By](#trusted-by)
|
||||||
* [Quick Start](#quick-start)
|
* [Quick Start](#quick-start)
|
||||||
* [Editor Integration](#editor-integration)
|
* [Editor Integration](#editor-integration)
|
||||||
|
* [Shell Completion](#shell-completion)
|
||||||
* [Comparison](#comparison)
|
* [Comparison](#comparison)
|
||||||
* [Performance](#performance)
|
* [Performance](#performance)
|
||||||
* [Internals](#internals)
|
* [Internals](#internals)
|
||||||
@ -217,6 +218,35 @@ golangci-lint run --disable-all -E errcheck
|
|||||||
* ale [merged pull request](https://github.com/w0rp/ale/pull/1890) with golangci-lint support
|
* ale [merged pull request](https://github.com/w0rp/ale/pull/1890) with golangci-lint support
|
||||||
6. Atom - [go-plus](https://atom.io/packages/go-plus) supports golangci-lint.
|
6. Atom - [go-plus](https://atom.io/packages/go-plus) supports golangci-lint.
|
||||||
|
|
||||||
|
## Shell Completion
|
||||||
|
|
||||||
|
`golangci-lint` can generate bash completion file.
|
||||||
|
|
||||||
|
### Mac OS X
|
||||||
|
|
||||||
|
Yhere are two versions of `bash-completion`, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The `golangci-lint` completion script doesn’t work correctly with bash-completion v1 and Bash 3.2. It requires bash-completion v2 and Bash 4.1+. Thus, to be able to correctly use `golangci-lint` completion on macOS, you have to install and use Bash 4.1+ ([instructions](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer).
|
||||||
|
|
||||||
|
Install `bash-completion v2`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install bash-completion@2
|
||||||
|
echo 'export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"' >>~/.bashrc
|
||||||
|
echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >>~/.bashrc
|
||||||
|
exec bash # reload and replace (if it was updated) shell
|
||||||
|
type _init_completion && echo "completion is OK" # verify that bash-completion v2 is correctly installed
|
||||||
|
```
|
||||||
|
|
||||||
|
Add `golangci-lint` bash completion:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo 'source <(golangci-lint completion bash)' >>~/.bashrc
|
||||||
|
source ~/.bashrc
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux
|
||||||
|
|
||||||
|
See [kubectl instructions](https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion) and don't forget to replace `kubectl` with `golangci-lint`.
|
||||||
|
|
||||||
## Comparison
|
## Comparison
|
||||||
|
|
||||||
### `golangci-lint` vs `gometalinter`
|
### `golangci-lint` vs `gometalinter`
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *Executor) initCompletion() {
|
func (e *Executor) initCompletion() {
|
||||||
completionCmd := &cobra.Command{
|
completionCmd := &cobra.Command{
|
||||||
Use: "completion",
|
Use: "completion",
|
||||||
Short: "Generates bash completion scripts",
|
Short: "Output completion script",
|
||||||
RunE: e.executeCompletion,
|
|
||||||
}
|
}
|
||||||
e.rootCmd.AddCommand(completionCmd)
|
e.rootCmd.AddCommand(completionCmd)
|
||||||
|
|
||||||
|
bashCmd := &cobra.Command{
|
||||||
|
Use: "bash",
|
||||||
|
Short: "Output bash completion script",
|
||||||
|
RunE: e.executeCompletion,
|
||||||
|
}
|
||||||
|
completionCmd.AddCommand(bashCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) executeCompletion(cmd *cobra.Command, args []string) error {
|
func (e *Executor) executeCompletion(cmd *cobra.Command, args []string) error {
|
||||||
err := cmd.Root().GenBashCompletion(os.Stdout)
|
err := cmd.Root().GenBashCompletion(os.Stdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to generate bash completions: %v", err)
|
return errors.Wrap(err, "unable to generate bash completions: %v")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user