Skip to content

Commit

Permalink
feat: support to trim the version prefix (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Mar 31, 2023
1 parent 8c6ea86 commit 1d26318
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func newCheckoutCommand() (c *cobra.Command) {
flags.IntVarP(&opt.pr, "pr", "p", -1, "The pr number want to checkout, -1 means do nothing")
flags.StringVarP(&opt.target, "target", "", ".", "Clone git repository to the target path")
flags.StringVarP(&opt.versionOutput, "version-output", "", "", "Write the version to target file")
flags.StringVarP(&opt.trimVersionPrefix, "version-trim-prefix", "", "", "Trim the prefix of the version")
return
}

Expand Down Expand Up @@ -132,7 +133,7 @@ func (o *checkoutOption) runE(c *cobra.Command, args []string) (err error) {
var head *plumbing.Reference
if head, err = repo.Head(); err == nil {
if o.versionOutput != "" {
err = os.WriteFile(o.versionOutput, []byte(head.Name().Short()), 0444)
err = os.WriteFile(o.versionOutput, []byte(strings.TrimPrefix(head.Name().Short(), o.trimVersionPrefix)), 0444)
}
}
}
Expand Down Expand Up @@ -167,12 +168,13 @@ func prRef(pr int, kind string) (ref string) {
}

type checkoutOption struct {
url string
remote string
branch string
tag string
pr int
target string
versionOutput string
sshPrivateKey string
url string
remote string
branch string
tag string
pr int
target string
sshPrivateKey string
versionOutput string
trimVersionPrefix string
}

0 comments on commit 1d26318

Please sign in to comment.