From 5b9cfbf91cc45d42715d44cf34d24c004b9d5087 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 00:46:57 +0900 Subject: [PATCH 1/2] Add `--match` option --- cmd/root.go | 1 + gh/gh.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index b5cc0aa..3e74cd9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -85,4 +85,5 @@ func init() { rootCmd.Flags().StringVarP(&opt.Version, "release-version", "V", "", "release version") rootCmd.Flags().StringVarP(&opt.OS, "os", "O", "", "specify OS of asset") rootCmd.Flags().StringVarP(&opt.Arch, "arch", "A", "", "specify arch of asset") + rootCmd.Flags().StringVarP(&opt.Match, "match", "A", "", "match string for asset") } diff --git a/gh/gh.go b/gh/gh.go index 2a73348..14bfc44 100644 --- a/gh/gh.go +++ b/gh/gh.go @@ -81,8 +81,11 @@ func GetReleaseAsset(ctx context.Context, owner, repo string, opt *AssetOption) func detectAsset(assets []*github.ReleaseAsset, opt *AssetOption) (*github.ReleaseAsset, error) { var ( - od, ad *regexp.Regexp + od, ad, om *regexp.Regexp ) + if opt != nil && opt.Match != "" { + om = regexp.MustCompile(opt.Match) + } if opt != nil && opt.OS != "" { od = getDictRegexp(opt.OS, osDict) } else { @@ -100,6 +103,9 @@ func detectAsset(assets []*github.ReleaseAsset, opt *AssetOption) (*github.Relea } assetScores := []*assetScore{} for _, a := range assets { + if om != nil && om.MatchString(a.GetName()) { + return a, nil + } if !contains(supportContentType, a.GetContentType()) { continue } From 153c340992d794d3876499e5c518de5fbcef1d9c Mon Sep 17 00:00:00 2001 From: k1LoW Date: Mon, 13 Feb 2023 00:48:26 +0900 Subject: [PATCH 2/2] Fix --- cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 3e74cd9..7fa55e8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -85,5 +85,5 @@ func init() { rootCmd.Flags().StringVarP(&opt.Version, "release-version", "V", "", "release version") rootCmd.Flags().StringVarP(&opt.OS, "os", "O", "", "specify OS of asset") rootCmd.Flags().StringVarP(&opt.Arch, "arch", "A", "", "specify arch of asset") - rootCmd.Flags().StringVarP(&opt.Match, "match", "A", "", "match string for asset") + rootCmd.Flags().StringVarP(&opt.Match, "match", "", "", "match string for asset") }