From 398460201e6fcbfe6a8d766b4299699c77ebe603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Thu, 15 Oct 2020 22:07:36 +0100 Subject: [PATCH] Refactored output --- z/database.go | 6 +++--- z/entry.go | 16 ++++++++-------- z/finish.go | 12 ++++++------ z/root.go | 9 ++++++++- z/track.go | 10 +++++----- z/tracking.go | 8 ++++---- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/z/database.go b/z/database.go index 4cabf9c..307f6e7 100644 --- a/z/database.go +++ b/z/database.go @@ -35,7 +35,7 @@ func InitDatabase() (*Database, error) { func (database *Database) NewID() (string) { id, err := uuid.NewRandom() if err != nil { - log.Fatalln("Could not generate UUID: %+v", err) + log.Fatalln("could not generate UUID: %+v", err) } return id.String() } @@ -91,11 +91,11 @@ func (database *Database) FinishEntry(user string, entry Entry) (string, error) dberr := database.DB.Update(func(tx *buntdb.Tx) error { runningEntryId, grerr := tx.Get(user + ":status:running") if grerr != nil { - return errors.New("No currently running entry found!") + return errors.New("no currently running entry found!") } if runningEntryId != entry.ID { - return errors.New("Specified entry is not currently running!") + return errors.New("specified entry is not currently running!") } _, _, srerr := tx.Set(user + ":status:running", "", nil) diff --git a/z/entry.go b/z/entry.go index c6e840b..c033976 100644 --- a/z/entry.go +++ b/z/entry.go @@ -103,14 +103,14 @@ func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string) } if entry.Task != "" && entry.Project != "" { - return fmt.Sprintf("▷ %s %s on %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix) + return fmt.Sprintf("%s %s %s on %s%s\n", CharTrack, outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix) } else if entry.Task != "" && entry.Project == "" { - return fmt.Sprintf("▷ %s %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), outputSuffix) + return fmt.Sprintf("%s %s %s%s\n", CharTrack, outputPrefix, color.FgLightWhite.Render(entry.Task), outputSuffix) } else if entry.Task == "" && entry.Project != "" { - return fmt.Sprintf("▷ %s task on %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Project), outputSuffix) + return fmt.Sprintf("%s %s task on %s%s\n", CharTrack, outputPrefix, color.FgLightWhite.Render(entry.Project), outputSuffix) } - return fmt.Sprintf("▷ %s task%s\n", outputPrefix, outputSuffix) + return fmt.Sprintf("%s %s task%s\n", CharTrack, outputPrefix, outputSuffix) } func (entry *Entry) GetOutputForFinish() (string) { @@ -122,12 +122,12 @@ func (entry *Entry) GetOutputForFinish() (string) { outputSuffix = fmt.Sprintf(" for %sh", color.FgLightWhite.Render(trackDiffOut.Format("15:04"))) if entry.Task != "" && entry.Project != "" { - return fmt.Sprintf("□ finished tracking %s on %s%s\n", color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix) + return fmt.Sprintf("%s finished tracking %s on %s%s\n", CharFinish, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix) } else if entry.Task != "" && entry.Project == "" { - return fmt.Sprintf("□ finished tracking %s%s\n", color.FgLightWhite.Render(entry.Task), outputSuffix) + return fmt.Sprintf("%s finished tracking %s%s\n", CharFinish, color.FgLightWhite.Render(entry.Task), outputSuffix) } else if entry.Task == "" && entry.Project != "" { - return fmt.Sprintf("□ finished tracking task on %s%s\n", color.FgLightWhite.Render(entry.Project), outputSuffix) + return fmt.Sprintf("%s finished tracking task on %s%s\n", CharFinish, color.FgLightWhite.Render(entry.Project), outputSuffix) } - return fmt.Sprintf("□ finished tracking task%s\n", outputSuffix) + return fmt.Sprintf("%s finished tracking task%s\n", CharFinish, outputSuffix) } diff --git a/z/finish.go b/z/finish.go index 8bfd3ef..5beef84 100644 --- a/z/finish.go +++ b/z/finish.go @@ -16,24 +16,24 @@ var finishCmd = &cobra.Command{ runningEntryId, err := database.GetRunningEntryId(user) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } if runningEntryId == "" { - fmt.Printf("□ not running\n") + fmt.Printf("%s not running\n", CharFinish) os.Exit(1) } runningEntry, err := database.GetEntry(user, runningEntryId) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } tmpEntry, err := NewEntry(runningEntry.ID, begin, finish, project, task, user) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } @@ -57,7 +57,7 @@ var finishCmd = &cobra.Command{ _, err = database.FinishEntry(user, runningEntry) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } @@ -76,7 +76,7 @@ func init() { var err error database, err = InitDatabase() if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } } diff --git a/z/root.go b/z/root.go index edc71ba..b676a25 100644 --- a/z/root.go +++ b/z/root.go @@ -15,6 +15,13 @@ var task string var force bool +const( + CharTrack = "▶" + CharFinish = "■" + CharErase = "◀" + CharError = "▲" +) + var rootCmd = &cobra.Command{ Use: "zeit", Short: "Command line Zeiterfassung", @@ -23,7 +30,7 @@ var rootCmd = &cobra.Command{ func Execute() { if err := rootCmd.Execute(); err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(-1) } } diff --git a/z/track.go b/z/track.go index cf6ee87..3f30426 100644 --- a/z/track.go +++ b/z/track.go @@ -15,18 +15,18 @@ var trackCmd = &cobra.Command{ runningEntryId, err := database.GetRunningEntryId(user) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } if runningEntryId != "" { - fmt.Printf("▷ a task is already running\n") + fmt.Printf("%s a task is already running\n", CharTrack) os.Exit(1) } newEntry, err := NewEntry("", begin, finish, project, task, user) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } @@ -34,7 +34,7 @@ var trackCmd = &cobra.Command{ _, err = database.AddEntry(user, newEntry, isRunning) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } @@ -54,7 +54,7 @@ func init() { var err error database, err = InitDatabase() if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } } diff --git a/z/tracking.go b/z/tracking.go index 2e41a9d..bee6cc2 100644 --- a/z/tracking.go +++ b/z/tracking.go @@ -15,18 +15,18 @@ var trackingCmd = &cobra.Command{ runningEntryId, err := database.GetRunningEntryId(user) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } if runningEntryId == "" { - fmt.Printf("□ not running\n") + fmt.Printf("%s not running\n", CharFinish) os.Exit(1) } runningEntry, err := database.GetEntry(user, runningEntryId) if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } @@ -41,7 +41,7 @@ func init() { var err error database, err = InitDatabase() if err != nil { - fmt.Printf("△ %+v\n", err) + fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } }