From e7d596b4e06de3175334e491f7d9580a097e1091 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sat, 9 Dec 2023 18:56:23 +0100 Subject: [PATCH] Allow specifying --timestamp 0 --- cmd/beam_listens.go | 4 +++- internal/cli/transfer.go | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/beam_listens.go b/cmd/beam_listens.go index 1b83e29..149319f 100644 --- a/cmd/beam_listens.go +++ b/cmd/beam_listens.go @@ -17,6 +17,8 @@ Scotty. If not, see . package cmd import ( + "math" + "github.com/spf13/cobra" "go.uploadedlobster.com/scotty/internal/backends" "go.uploadedlobster.com/scotty/internal/cli" @@ -58,5 +60,5 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: // beamListensCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") - beamListensCmd.Flags().Int64P("timestamp", "t", 0, "Only import listens newer then given Unix timestamp") + beamListensCmd.Flags().Int64P("timestamp", "t", math.MinInt64, "Only import listens newer then given Unix timestamp") } diff --git a/internal/cli/transfer.go b/internal/cli/transfer.go index 757b912..6636bce 100644 --- a/internal/cli/transfer.go +++ b/internal/cli/transfer.go @@ -17,6 +17,7 @@ package cli import ( "fmt" + "math" "sync" "time" @@ -153,12 +154,13 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac } func (c *TransferCmd[E, I, R]) timestamp() (time.Time, error) { - timestamp := time.Unix(getInt64FromFlag(c.cmd, "timestamp"), 0) - if timestamp == time.Unix(0, 0) { + flagValue, err := c.cmd.Flags().GetInt64("timestamp") + if err == nil && flagValue > math.MinInt64 { + return time.Unix(flagValue, 0), nil + } else { timestamp, err := c.db.GetImportTimestamp(c.sourceName, c.targetName, c.entity) return timestamp, err } - return timestamp, nil } func (c *TransferCmd[E, I, R]) updateTimestamp(result models.ImportResult, oldTimestamp time.Time) error {