From 5dd03146b219ca548b6f66d17881b40f28dcdd13 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 13:17:58 +0100 Subject: [PATCH] Extended finish command with notes and Git log import --- z/finish.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/z/finish.go b/z/finish.go index 5beef84..2cf7c42 100644 --- a/z/finish.go +++ b/z/finish.go @@ -55,6 +55,32 @@ var finishCmd = &cobra.Command{ runningEntry.Task = tmpEntry.Task } + if notes != "" { + runningEntry.Notes = fmt.Sprintf("%s\n%s", runningEntry.Notes, notes) + } + + if runningEntry.Task != "" { + task, err := database.GetTask(user, runningEntry.Task) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + if task.GitRepository != "" && task.GitRepository != "-" { + stdout, stderr, err := GetGitLog(task.GitRepository, runningEntry.Begin, runningEntry.Finish) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + if stderr == "" { + runningEntry.Notes = fmt.Sprintf("%s\n%s", runningEntry.Notes, stdout) + } else { + fmt.Printf("%s notes were not imported: %+v\n", CharError, stderr) + } + } + } + _, err = database.FinishEntry(user, runningEntry) if err != nil { fmt.Printf("%s %+v\n", CharError, err) @@ -71,6 +97,7 @@ func init() { finishCmd.Flags().StringVarP(&begin, "begin", "b", "", "Time the activity should begin 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).") finishCmd.Flags().StringVarP(&finish, "finish", "s", "", "Time the activity should finish 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.") finishCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be assigned") + finishCmd.Flags().StringVarP(¬es, "notes", "n", "", "Activity notes") finishCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned") var err error