From fda944ab17d4f53d1146df6bbcfd1ac8c15c81c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 17 Oct 2020 20:06:25 +0100 Subject: [PATCH] Consolidated list/export further, extended list command --- z/export.go | 21 +++++++++------------ z/list.go | 33 ++++++++++++++++++++++++++++++++- z/root.go | 3 +++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/z/export.go b/z/export.go index 2a676bf..48748a1 100644 --- a/z/export.go +++ b/z/export.go @@ -8,9 +8,6 @@ import ( "github.com/spf13/cobra" ) -var exportSince string -var exportUntil string - func exportZeitJson(user string, entries []Entry) (string, error) { stringified, err := json.Marshal(entries) if err != nil { @@ -47,19 +44,19 @@ var exportCmd = &cobra.Command{ os.Exit(1) } - var since time.Time - var until time.Time + var sinceTime time.Time + var untilTime time.Time - if exportSince != "" { - since, err = time.Parse(time.RFC3339, exportSince) + if since != "" { + sinceTime, err = time.Parse(time.RFC3339, since) if err != nil { fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } } - if exportUntil != "" { - until, err = time.Parse(time.RFC3339, exportUntil) + if until != "" { + untilTime, err = time.Parse(time.RFC3339, until) if err != nil { fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) @@ -67,7 +64,7 @@ var exportCmd = &cobra.Command{ } var filteredEntries []Entry - filteredEntries, err = GetFilteredEntries(entries, project, task, since, until) + filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime) if err != nil { fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) @@ -100,8 +97,8 @@ var exportCmd = &cobra.Command{ func init() { rootCmd.AddCommand(exportCmd) exportCmd.Flags().StringVar(&format, "format", "", "Format to export, possible values: zeit, tyme") - exportCmd.Flags().StringVar(&exportSince, "since", "", "Date/time to start the export from") - exportCmd.Flags().StringVar(&exportUntil, "until", "", "Date/time to export until") + exportCmd.Flags().StringVar(&since, "since", "", "Date/time to start the export from") + exportCmd.Flags().StringVar(&until, "until", "", "Date/time to export until") exportCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be exported") exportCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be exported") diff --git a/z/list.go b/z/list.go index 9353037..de2c23f 100644 --- a/z/list.go +++ b/z/list.go @@ -3,6 +3,7 @@ package z import ( "os" "fmt" + "time" "github.com/spf13/cobra" ) @@ -19,7 +20,33 @@ var listCmd = &cobra.Command{ os.Exit(1) } - for _, entry := range entries { + var sinceTime time.Time + var untilTime time.Time + + if since != "" { + sinceTime, err = time.Parse(time.RFC3339, since) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + } + + if until != "" { + untilTime, err = time.Parse(time.RFC3339, until) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + } + + var filteredEntries []Entry + filteredEntries, err = GetFilteredEntries(entries, project, task, sinceTime, untilTime) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + for _, entry := range filteredEntries { fmt.Printf("%s\n", entry.GetOutput()) } @@ -29,6 +56,10 @@ var listCmd = &cobra.Command{ func init() { rootCmd.AddCommand(listCmd) + listCmd.Flags().StringVar(&since, "since", "", "Date/time to start the list from") + listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until") + listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed") + listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed") var err error database, err = InitDatabase() diff --git a/z/root.go b/z/root.go index 3cab1d6..c0148b1 100644 --- a/z/root.go +++ b/z/root.go @@ -14,6 +14,9 @@ var project string var task string var notes string +var since string +var until string + var format string var force bool