mirror of
https://github.com/rsteube/carapace-bin.git
synced 2025-05-05 15:32:53 +00:00
goreleaser: complete build ids
This commit is contained in:
parent
4e1fecda0f
commit
5e13706fef
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/goreleaser"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -36,9 +37,11 @@ func init() {
|
||||
buildCmd.Flag("skip-validate").Hidden = true
|
||||
rootCmd.AddCommand(buildCmd)
|
||||
|
||||
// TODO build ids
|
||||
carapace.Gen(buildCmd).FlagCompletion(carapace.ActionMap{
|
||||
"config": carapace.ActionFiles(),
|
||||
"id": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
return goreleaser.ActionBuilds(buildCmd.Flag("config").Value.String()).UniqueList(",")
|
||||
}),
|
||||
"output": carapace.ActionFiles(),
|
||||
"skip": carapace.ActionValues("before", "post-hooks", "pre-hooks", "validate").UniqueList(","),
|
||||
})
|
||||
|
45
pkg/actions/tools/goreleaser/build.go
Normal file
45
pkg/actions/tools/goreleaser/build.go
Normal file
@ -0,0 +1,45 @@
|
||||
package goreleaser
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/carapace-sh/carapace"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type goreleaserConfig struct {
|
||||
Builds []struct {
|
||||
Id string
|
||||
}
|
||||
}
|
||||
|
||||
// ActionBuilds completes build ids.
|
||||
//
|
||||
// default
|
||||
// termux
|
||||
func ActionBuilds(path string) carapace.Action {
|
||||
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||
if path == "" {
|
||||
path = ".goreleaser.yaml"
|
||||
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
|
||||
path = ".goreleaser.yml"
|
||||
}
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return carapace.ActionMessage(err.Error())
|
||||
}
|
||||
|
||||
var config goreleaserConfig
|
||||
if err := yaml.Unmarshal(content, &config); err != nil {
|
||||
return carapace.ActionMessage(err.Error())
|
||||
}
|
||||
|
||||
vals := make([]string, 0)
|
||||
for _, build := range config.Builds {
|
||||
vals = append(vals, build.Id)
|
||||
}
|
||||
return carapace.ActionValues(vals...)
|
||||
}).Tag("builds")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user