Extended finish command with notes and Git log import

This commit is contained in:
マリウス 2020-10-17 13:17:58 +01:00
parent b50277d9ce
commit 5dd03146b2
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -55,6 +55,32 @@ var finishCmd = &cobra.Command{
runningEntry.Task = tmpEntry.Task 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) _, err = database.FinishEntry(user, runningEntry)
if err != nil { if err != nil {
fmt.Printf("%s %+v\n", CharError, err) 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(&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(&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(&project, "project", "p", "", "Project to be assigned")
finishCmd.Flags().StringVarP(&notes, "notes", "n", "", "Activity notes")
finishCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned") finishCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
var err error var err error