Skip to content

Commit

Permalink
Merge pull request #12 from k1LoW/match
Browse files Browse the repository at this point in the history
Add `--match` option
  • Loading branch information
k1LoW authored Feb 12, 2023
2 parents 691a358 + 153c340 commit 9d5ae21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
8 changes: 7 additions & 1 deletion gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 9d5ae21

Please sign in to comment.