1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

refactor: improve --skip completions

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-09-17 03:00:15 +00:00
parent 5767a3bd1e
commit 0337a0b3a8
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 14 additions and 19 deletions

View File

@ -5,7 +5,6 @@ import (
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"time"
@ -127,14 +126,7 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
fmt.Sprintf("Skip the given options (valid options are %s)", skips.Build.String()),
)
_ = cmd.RegisterFlagCompletionFunc("skip", func(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var result []string
for _, k := range skips.Build {
if strings.HasPrefix(string(k), strings.ToLower(toComplete)) {
result = append(result, string(k))
}
}
sort.Strings(result)
return result, cobra.ShellCompDirectiveDefault
return skips.Build.Complete(toComplete), cobra.ShellCompDirectiveDefault
})
root.cmd = cmd

View File

@ -3,8 +3,6 @@ package cmd
import (
"fmt"
"runtime"
"sort"
"strings"
"time"
"github.com/caarlos0/ctrlc"
@ -138,14 +136,7 @@ func newReleaseCmd() *releaseCmd {
fmt.Sprintf("Skip the given options (valid options are %s)", skips.Release.String()),
)
_ = cmd.RegisterFlagCompletionFunc("skip", func(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var result []string
for _, k := range skips.Release {
if strings.HasPrefix(string(k), strings.ToLower(toComplete)) {
result = append(result, string(k))
}
}
sort.Strings(result)
return result, cobra.ShellCompDirectiveDefault
return skips.Release.Complete(toComplete), cobra.ShellCompDirectiveDefault
})
root.cmd = cmd

View File

@ -2,6 +2,7 @@ package skips
import (
"fmt"
"sort"
"strings"
"github.com/goreleaser/goreleaser/pkg/context"
@ -65,6 +66,17 @@ func (keys Keys) String() string {
return strings.Join(ss, ", ")
}
func (keys Keys) Complete(prefix string) []string {
var result []string
for _, k := range keys {
if strings.HasPrefix(string(k), strings.ToLower(prefix)) {
result = append(result, string(k))
}
}
sort.Strings(result)
return result
}
var Release = Keys{
Publish,
Announce,