From dd33469605d2154f400f6a12c2d39d29a37eaf24 Mon Sep 17 00:00:00 2001 From: Philipp Rosenkranz Date: Tue, 2 Apr 2019 17:41:16 +0200 Subject: [PATCH] return after error --- cmd-config.go | 3 ++- cmd-entries.go | 26 ++++++++++++++++++++++++-- cmd-projects.go | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd-config.go b/cmd-config.go index 7b41355..124307a 100644 --- a/cmd-config.go +++ b/cmd-config.go @@ -27,9 +27,10 @@ var configCommand = &cobra.Command{ err := viper.ReadInConfig() if err != nil { _, _ = fmt.Fprintln(os.Stderr, err) + return } if containsEquals { - // write to config + // write listTo config configKeyValue := strings.Split(firstArgument, "=") configKey := configKeyValue[0] configValue := configKeyValue[1] diff --git a/cmd-entries.go b/cmd-entries.go index 1f28d5a..0b9c509 100644 --- a/cmd-entries.go +++ b/cmd-entries.go @@ -10,7 +10,18 @@ import ( "time" ) +var ( + listTo string + listFrom string + listOrder string +) + func init() { + defaultTo := time.Now() + defaultFrom := defaultTo.AddDate(0, 0, -7) + entriesListCommand.Flags().StringVarP(&listTo, "to", "t", defaultTo.Format("2006-01-02"), "list only entries until date (in YYYY-MM-DD format)") + entriesListCommand.Flags().StringVarP(&listFrom, "from", "f", defaultFrom.Format("2006-01-02"), "list only entries starting at date (in YYYY-MM-DD format)") + entriesListCommand.Flags().StringVarP(&listOrder, "order", "o", "asc", "list only entries starting at date (in YYYY-MM-DD format)") entriesCommand.AddCommand(entriesListCommand) rootCmd.AddCommand(entriesCommand) } @@ -26,10 +37,20 @@ var entriesListCommand = &cobra.Command{ Short: "list time entries", Run: func(cmd *cobra.Command, args []string) { api := mite.NewMiteApi(configGetApiUrl(), configGetApiKey()) - to := time.Now() - from := to.AddDate(0, 0, -7) + direction := mite.DirectionAsc + to, err := time.Parse("2006-01-02", listTo) + if err != nil { + _, _ = fmt.Fprintln(os.Stderr, err) + return + } + from, err := time.Parse("2006-01-02", listFrom) + if err != nil { + _, _ = fmt.Fprintln(os.Stderr, err) + return + } + entries, err := api.TimeEntries(&mite.TimeEntryParameters{ To: &to, From: &from, @@ -37,6 +58,7 @@ var entriesListCommand = &cobra.Command{ }) if err != nil { _, _ = fmt.Fprintln(os.Stderr, err) + return } t := tabby.New() diff --git a/cmd-projects.go b/cmd-projects.go index 7694871..e73c0c1 100644 --- a/cmd-projects.go +++ b/cmd-projects.go @@ -27,6 +27,7 @@ var listProjectsCommand = &cobra.Command{ projects, err := api.Projects() if err != nil { _, _ = fmt.Fprintln(os.Stderr, err) + return } t := tabby.New()