Refactored entry update

This commit is contained in:
マリウス 2020-10-17 22:49:29 +01:00
parent 94f062e036
commit 3f23b28662
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -3,6 +3,7 @@ package z
import ( import (
"os" "os"
"fmt" "fmt"
"time"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -23,26 +24,28 @@ var entryCmd = &cobra.Command{
} }
if begin != "" || finish != "" || project != "" || notes != "" || task != "" { if begin != "" || finish != "" || project != "" || notes != "" || task != "" {
tmpEntry, err := NewEntry(entry.ID, begin, finish, project, task, user) if begin != "" {
entry.Begin, err = time.Parse(time.RFC3339, begin)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1) os.Exit(1)
} }
if begin != "" {
entry.Begin = tmpEntry.Begin
} }
if finish != "" { if finish != "" {
entry.Finish = tmpEntry.Finish entry.Finish, err = time.Parse(time.RFC3339, finish)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
} }
if project != "" { if project != "" {
entry.Project = tmpEntry.Project entry.Project = project
} }
if task != "" { if task != "" {
entry.Task = tmpEntry.Task entry.Task = task
} }
if notes != "" { if notes != "" {
@ -63,8 +66,8 @@ var entryCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(entryCmd) rootCmd.AddCommand(entryCmd)
entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update time the activity began at\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).") entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at\n\nUse RFC3339 format.")
entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update time the activity finished at\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).\nMust be after --begin time.") entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at\n\nUse RFC3339 format.")
entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project") entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project")
entryCmd.Flags().StringVarP(&notes, "notes", "n", "", "Update activity notes") entryCmd.Flags().StringVarP(&notes, "notes", "n", "", "Update activity notes")
entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task") entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task")