Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into latest-nfpm-config
- Loading branch information
Showing
12 changed files
with
113 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
type completionCmd struct { | ||
cmd *cobra.Command | ||
} | ||
|
||
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), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
switch args[0] { | ||
case "bash": | ||
err = cmd.Root().GenBashCompletion(cmd.OutOrStdout()) | ||
case "zsh": | ||
err = cmd.Root().GenZshCompletion(cmd.OutOrStdout()) | ||
case "fish": | ||
err = cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true) | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
|
||
root.cmd = cmd | ||
return root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCompletionGeneration(t *testing.T) { | ||
for _, shell := range []string{"bash", "zsh", "fish"} { | ||
t.Run(shell, func(t *testing.T) { | ||
completionCmd := newCompletionCmd().cmd | ||
stdout := bytes.NewBufferString("") | ||
stderr := bytes.NewBufferString("") | ||
completionCmd.SetOut(stdout) | ||
completionCmd.SetErr(stderr) | ||
completionCmd.SetArgs([]string{shell}) | ||
err := completionCmd.Execute() | ||
require.NoError(t, err, shell+" arg experienced error with goreleaser completion:\n"+stderr.String()) | ||
require.Equal(t, "", stderr.String(), shell+" arg experienced error with goreleaser completion:\n"+stderr.String()) | ||
require.NotEmpty(t, stdout.String(), shell+" arg reported nothing to stdout with goreleaser completion") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters