Skip to content

Commit

Permalink
feat: support to output the timestamp (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen committed Apr 12, 2024
1 parent b7dacce commit 6745e92
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/go-git/go-git/v5/plumbing/transport/http"

Expand Down Expand Up @@ -41,6 +42,8 @@ func newCheckoutCommand() (c *cobra.Command) {
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")
flags.StringVarP(&opt.timestampOutput, "timestamp-output", "", "", "Write the current time to the target file")
flags.StringVarP(&opt.timestampFormat, "timestamp-format", "", "2006-01-02-150405", "The format of the time stamp")
return
}

Expand Down Expand Up @@ -139,6 +142,14 @@ func (o *checkoutOption) runE(c *cobra.Command, args []string) (err error) {
if o.versionOutput != "" {
err = os.WriteFile(o.versionOutput, []byte(strings.TrimPrefix(version, o.trimVersionPrefix)), 0444)
}

switch o.timestampOutput {
case "":
case "-":
_, err = fmt.Fprint(c.OutOrStdout(), time.Now().Format(o.timestampFormat))
default:
err = os.WriteFile(o.timestampOutput, []byte(time.Now().Format(o.timestampFormat)), 0444)
}
}
return
}
Expand Down Expand Up @@ -185,6 +196,8 @@ type checkoutOption struct {
sshPrivateKey string
versionOutput string
trimVersionPrefix string
timestampOutput string
timestampFormat string
username string
password string
}
Loading

0 comments on commit 6745e92

Please sign in to comment.