Skip to content

Commit

Permalink
goreleaser: complete build ids
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Oct 24, 2024
1 parent 4e1fecd commit e9fbdbe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions completers/goreleaser_completer/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -39,6 +40,9 @@ func init() {
// 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())
}),
"output": carapace.ActionFiles(),
"skip": carapace.ActionValues("before", "post-hooks", "pre-hooks", "validate").UniqueList(","),
})
Expand Down
45 changes: 45 additions & 0 deletions pkg/actions/tools/goreleaser/build.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit e9fbdbe

Please sign in to comment.