1
0
Fork 0
mirror of https://git.sr.ht/~phw/scotty synced 2025-04-21 04:19:27 +02:00

Implemented "beam --timestamp {n}"

This commit is contained in:
Philipp Wolfer 2023-11-13 19:11:19 +01:00
parent 4d18a207ee
commit 27685d617a
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
4 changed files with 11 additions and 2 deletions

View file

@ -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.:

View file

@ -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
}

View file

@ -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)

View file

@ -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)