diff --git a/cmd/beam.go b/cmd/beam.go index 8645d7d..c38703d 100644 --- a/cmd/beam.go +++ b/cmd/beam.go @@ -47,6 +47,7 @@ func init() { beamCmd.MarkPersistentFlagRequired("from") beamCmd.PersistentFlags().StringP("to", "t", "", "Target backend configuration (required)") beamCmd.MarkPersistentFlagRequired("to") + beamCmd.PersistentFlags().Int64P("timestamp", "s", 0, "Only import data newer then given Unix timestamp") // Cobra supports local flags which will only run when this command // is called directly, e.g.: diff --git a/cmd/common.go b/cmd/common.go index 79242be..ff31fec 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -36,3 +36,11 @@ func getConfigFromFlag(cmd *cobra.Command, flagName string) (string, *viper.Vipe } return configName, config } + +func getInt64FromFlag(cmd *cobra.Command, flagName string) (result int64) { + result, err := cmd.Flags().GetInt64(flagName) + if err != nil { + result = 0 + } + return +} diff --git a/cmd/listens.go b/cmd/listens.go index ef08ade..b54bf61 100644 --- a/cmd/listens.go +++ b/cmd/listens.go @@ -43,7 +43,7 @@ var listensCmd = &cobra.Command{ cobra.CheckErr(err) importBackend, err := backends.ResolveBackend[models.ListensImport](targetConfig) cobra.CheckErr(err) - timestamp := time.Unix(0, 0) + timestamp := time.Unix(getInt64FromFlag(cmd, "timestamp"), 0) listens, err := exportBackend.ExportListens(timestamp) cobra.CheckErr(err) result, err := importBackend.ImportListens(listens, timestamp) diff --git a/cmd/loves.go b/cmd/loves.go index 406f414..44b4c3c 100644 --- a/cmd/loves.go +++ b/cmd/loves.go @@ -43,7 +43,7 @@ var lovesCmd = &cobra.Command{ cobra.CheckErr(err) importBackend, err := backends.ResolveBackend[models.LovesImport](targetConfig) cobra.CheckErr(err) - timestamp := time.Unix(0, 0) + timestamp := time.Unix(getInt64FromFlag(cmd, "timestamp"), 0) loves, err := exportBackend.ExportLoves(timestamp) cobra.CheckErr(err) result, err := importBackend.ImportLoves(loves, timestamp)