-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2570 from carapace-sh/goreleaser-build-id
goreleaser: complete build ids
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
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
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") | ||
} |