Skip to content

Commit

Permalink
return after error
Browse files Browse the repository at this point in the history
  • Loading branch information
phiros committed Apr 2, 2019
1 parent 86d17be commit dd33469
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
26 changes: 24 additions & 2 deletions cmd-entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -26,17 +37,28 @@ 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,
Direction: &direction,
})
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
return
}

t := tabby.New()
Expand Down
1 change: 1 addition & 0 deletions cmd-projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var listProjectsCommand = &cobra.Command{
projects, err := api.Projects()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
return
}

t := tabby.New()
Expand Down

0 comments on commit dd33469

Please sign in to comment.