diff --git a/cmd/root.go b/cmd/root.go index b5cc0aa..7fa55e8 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", "", "", "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 }