From ce9a2538d6eabc3164007a00ddd9d5ced459ead9 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 5 Oct 2017 13:55:46 +0200 Subject: [PATCH] Added balance deletion --- patches/delete-balance/delete-balance.go | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 patches/delete-balance/delete-balance.go diff --git a/patches/delete-balance/delete-balance.go b/patches/delete-balance/delete-balance.go new file mode 100644 index 00000000..bc329500 --- /dev/null +++ b/patches/delete-balance/delete-balance.go @@ -0,0 +1,38 @@ +package main + +import ( + "flag" + + "github.com/animenotifier/arn" + "github.com/fatih/color" +) + +// Shell parameters +var confirmed bool + +// Shell flags +func init() { + flag.BoolVar(&confirmed, "confirm", false, "Confirm that you really want to execute this.") + flag.Parse() +} + +func main() { + if !confirmed { + color.Green("Please run this command with -confirm option if you really want to reset the balance of all users.") + return + } + + color.Yellow("Resetting balance of all users to 0") + + // Get a stream of all users + allUsers, err := arn.StreamUsers() + arn.PanicOnError(err) + + // Iterate over the stream + for user := range allUsers { + user.Balance = 0 + arn.PanicOnError(user.Save()) + } + + color.Green("Finished.") +}