From 1ebf9c043f589e4d8082916ce58eb9d6b7640de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 15 Oct 2020 22:45:14 +0100 Subject: [PATCH] Implemented list command --- z/list.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 z/list.go diff --git a/z/list.go b/z/list.go new file mode 100644 index 0000000..88ecf03 --- /dev/null +++ b/z/list.go @@ -0,0 +1,39 @@ +package z + +import ( + "os" + "fmt" + "github.com/spf13/cobra" +) + +var listCmd = &cobra.Command{ + Use: "list", + Short: "List activity", + Long: "List all tracked activity.", + Run: func(cmd *cobra.Command, args []string) { + user := GetCurrentUser() + + entries, err := database.ListEntries(user) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + for _, entry := range entries { + fmt.Printf("%s\n", entry.GetOutput()) + } + + return + }, +} + +func init() { + rootCmd.AddCommand(listCmd) + + var err error + database, err = InitDatabase() + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } +}