Skip to content

Commit

Permalink
fix: improve completions (#1894)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Nov 12, 2020
1 parent c39c820 commit 707639f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/build.go
Expand Up @@ -37,6 +37,7 @@ func newBuildCmd() *buildCmd {
Short: "Builds the current project",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
start := time.Now()

Expand Down
1 change: 1 addition & 0 deletions cmd/check.go
Expand Up @@ -25,6 +25,7 @@ func newCheckCmd() *checkCmd {
Short: "Checks if configuration is valid",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := loadConfig(root.config)
if err != nil {
Expand Down
42 changes: 37 additions & 5 deletions cmd/completion.go
Expand Up @@ -9,11 +9,43 @@ type completionCmd struct {
func newCompletionCmd() *completionCmd {
var root = &completionCmd{}
var cmd = &cobra.Command{
Use: "completion",
Short: "Print shell autocompletion scripts for goreleaser",
SilenceUsage: true,
ValidArgs: []string{"bash", "zsh", "fish"},
Args: cobra.ExactValidArgs(1),
Use: "completion [bash|zsh|fish]",
Short: "Print shell autocompletion scripts for goreleaser",
Long: `To load completions:
Bash:
$ source <(goreleaser completion bash)
# To load completions for each session, execute once:
Linux:
$ goreleaser completion bash > /etc/bash_completion.d/goreleaser
MacOS:
$ goreleaser completion bash > /usr/local/etc/bash_completion.d/goreleaser
Zsh:
# If shell completion is not already enabled in your environment you will need
# to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ goreleaser completion zsh > "${fpath[1]}/_goreleaser"
# You will need to start a new shell for this setup to take effect.
Fish:
$ goreleaser completion fish | source
# To load completions for each session, execute once:
$ goreleaser completion fish > ~/.config/fish/completions/goreleaser.fish
`,
SilenceUsage: true,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
switch args[0] {
Expand Down
1 change: 1 addition & 0 deletions cmd/init.go
Expand Up @@ -22,6 +22,7 @@ func newInitCmd() *initCmd {
Short: "Generates a .goreleaser.yml file",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
f, err := os.OpenFile(root.config, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, 0644)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/release.go
Expand Up @@ -41,6 +41,7 @@ func newReleaseCmd() *releaseCmd {
Short: "Releases the current project",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
start := time.Now()

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Expand Up @@ -62,6 +62,7 @@ func newRootCmd(version string, exit func(int)) *rootCmd {
Version: version,
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if root.debug {
log.SetLevel(log.DebugLevel)
Expand Down

1 comment on commit 707639f

@vercel
Copy link

@vercel vercel bot commented on 707639f Nov 12, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.