From 55a90954abd8305d69a6a134c2801627e8e19a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Fri, 16 Oct 2020 01:21:03 +0100 Subject: [PATCH] Implemented erase command --- z/erase.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 z/erase.go diff --git a/z/erase.go b/z/erase.go new file mode 100644 index 0000000..f2e51bc --- /dev/null +++ b/z/erase.go @@ -0,0 +1,39 @@ +package z + +import ( + "os" + "fmt" + "github.com/spf13/cobra" + "github.com/gookit/color" +) + +var eraseCmd = &cobra.Command{ + Use: "erase ([flags]) [id]", + Short: "Erase activity", + Long: "Erase tracked activity.", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + user := GetCurrentUser() + id := args[0] + + err := database.EraseEntry(user, id) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + fmt.Printf("%s erased %s\n", CharInfo, color.FgLightWhite.Render(id)) + return + }, +} + +func init() { + rootCmd.AddCommand(eraseCmd) + + var err error + database, err = InitDatabase() + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } +}