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:
parent
5767a3bd1e
commit
0337a0b3a8
10
cmd/build.go
10
cmd/build.go
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user