2020-10-17 20:14:49 +00:00
|
|
|
package z
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"fmt"
|
2020-10-17 21:49:29 +00:00
|
|
|
"time"
|
2020-10-17 20:14:49 +00:00
|
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var entryCmd = &cobra.Command{
|
|
|
|
Use: "entry ([flags]) [id]",
|
|
|
|
Short: "Display or update activity",
|
|
|
|
Long: "Display or update tracked activity.",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
user := GetCurrentUser()
|
|
|
|
id := args[0]
|
|
|
|
|
|
|
|
entry, err := database.GetEntry(user, id)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %+v\n", CharError, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if begin != "" || finish != "" || project != "" || notes != "" || task != "" {
|
|
|
|
if begin != "" {
|
2020-10-17 21:49:29 +00:00
|
|
|
entry.Begin, err = time.Parse(time.RFC3339, begin)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %+v\n", CharError, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-10-17 20:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if finish != "" {
|
2020-10-17 21:49:29 +00:00
|
|
|
entry.Finish, err = time.Parse(time.RFC3339, finish)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %+v\n", CharError, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-10-17 20:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if project != "" {
|
2020-10-17 21:49:29 +00:00
|
|
|
entry.Project = project
|
2020-10-17 20:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if task != "" {
|
2020-10-17 21:49:29 +00:00
|
|
|
entry.Task = task
|
2020-10-17 20:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if notes != "" {
|
|
|
|
entry.Notes = strings.Replace(notes, "\\n", "\n", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = database.UpdateEntry(user, entry)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %+v\n", CharError, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%s %s\n", CharInfo, entry.GetOutput(true))
|
|
|
|
return
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(entryCmd)
|
2020-10-17 21:49:29 +00:00
|
|
|
entryCmd.Flags().StringVarP(&begin, "begin", "b", "", "Update date/time the activity began at\n\nUse RFC3339 format.")
|
|
|
|
entryCmd.Flags().StringVarP(&finish, "finish", "s", "", "Update date/time the activity finished at\n\nUse RFC3339 format.")
|
2020-10-17 20:14:49 +00:00
|
|
|
entryCmd.Flags().StringVarP(&project, "project", "p", "", "Update activity project")
|
|
|
|
entryCmd.Flags().StringVarP(¬es, "notes", "n", "", "Update activity notes")
|
|
|
|
entryCmd.Flags().StringVarP(&task, "task", "t", "", "Update activity task")
|
|
|
|
|
|
|
|
var err error
|
|
|
|
database, err = InitDatabase()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %+v\n", CharError, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|