Refactored output
This commit is contained in:
parent
fc2c29cf52
commit
ce8d2766ff
3 changed files with 35 additions and 20 deletions
39
z/entry.go
39
z/entry.go
|
@ -85,34 +85,49 @@ func (entry *Entry) IsFinishedAfterBegan() (bool) {
|
||||||
return (entry.Finish.IsZero() || entry.Begin.Before(entry.Finish))
|
return (entry.Finish.IsZero() || entry.Begin.Before(entry.Finish))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) GetOutputForTrack(isRunning bool) (string) {
|
func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string) {
|
||||||
outputPrefix := "began tracking"
|
var outputPrefix string = ""
|
||||||
if isRunning == false {
|
var outputSuffix string = ""
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
trackDiffNow := now.Sub(entry.Begin)
|
||||||
|
trackDiffNowOut := time.Time{}.Add(trackDiffNow)
|
||||||
|
|
||||||
|
if isRunning == true && wasRunning == false {
|
||||||
|
outputPrefix = "began tracking"
|
||||||
|
} else if isRunning == true && wasRunning == true {
|
||||||
|
outputPrefix = "tracking"
|
||||||
|
outputSuffix = fmt.Sprintf(" for %sh", color.FgLightWhite.Render(trackDiffNowOut.Format("15:04")))
|
||||||
|
} else if isRunning == false && wasRunning == false {
|
||||||
outputPrefix = "tracked"
|
outputPrefix = "tracked"
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.Task != "" && entry.Project != "" {
|
if entry.Task != "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("▷ %s %s on %s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project))
|
return fmt.Sprintf("▷ %s %s on %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
} else if entry.Task != "" && entry.Project == "" {
|
} else if entry.Task != "" && entry.Project == "" {
|
||||||
return fmt.Sprintf("▷ %s %s\n", outputPrefix, color.FgLightWhite.Render(entry.Task))
|
return fmt.Sprintf("▷ %s %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), outputSuffix)
|
||||||
} else if entry.Task == "" && entry.Project != "" {
|
} else if entry.Task == "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("▷ %s task on %s\n", outputPrefix, color.FgLightWhite.Render(entry.Project))
|
return fmt.Sprintf("▷ %s task on %s%s\n", outputPrefix, color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("▷ %s task\n", outputPrefix)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("▷ %s task%s\n", outputPrefix, outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) GetOutputForFinish() (string) {
|
func (entry *Entry) GetOutputForFinish() (string) {
|
||||||
|
var outputSuffix string = ""
|
||||||
|
|
||||||
trackDiff := entry.Finish.Sub(entry.Begin)
|
trackDiff := entry.Finish.Sub(entry.Begin)
|
||||||
trackDiffOut := time.Time{}.Add(trackDiff)
|
trackDiffOut := time.Time{}.Add(trackDiff)
|
||||||
|
|
||||||
|
outputSuffix = fmt.Sprintf(" for %sh", color.FgLightWhite.Render(trackDiffOut.Format("15:04")))
|
||||||
|
|
||||||
if entry.Task != "" && entry.Project != "" {
|
if entry.Task != "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("□ finished tracking %s on %s for %sh\n", color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), trackDiffOut.Format("15:04"))
|
return fmt.Sprintf("□ finished tracking %s on %s%s\n", color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
} else if entry.Task != "" && entry.Project == "" {
|
} else if entry.Task != "" && entry.Project == "" {
|
||||||
return fmt.Sprintf("□ finished tracking %s for %sh\n", color.FgLightWhite.Render(entry.Task), trackDiffOut.Format("15:04"))
|
return fmt.Sprintf("□ finished tracking %s%s\n", color.FgLightWhite.Render(entry.Task), outputSuffix)
|
||||||
} else if entry.Task == "" && entry.Project != "" {
|
} else if entry.Task == "" && entry.Project != "" {
|
||||||
return fmt.Sprintf("□ finished tracking task on %s for %sh\n", color.FgLightWhite.Render(entry.Project), trackDiffOut.Format("15:04"))
|
return fmt.Sprintf("□ finished tracking task on %s%s\n", color.FgLightWhite.Render(entry.Project), outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("□ finished tracking task\n")
|
return fmt.Sprintf("□ finished tracking task%s\n", outputSuffix)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
var finishCmd = &cobra.Command{
|
var finishCmd = &cobra.Command{
|
||||||
Use: "finish",
|
Use: "finish",
|
||||||
Short: "Finish currently running tracker",
|
Short: "Finish currently running activity",
|
||||||
Long: "Finishing a currently running tracker.",
|
Long: "Finishing tracking of currently running activity.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
user := GetCurrentUser()
|
user := GetCurrentUser()
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ var finishCmd = &cobra.Command{
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(finishCmd)
|
rootCmd.AddCommand(finishCmd)
|
||||||
finishCmd.Flags().StringVarP(&begin, "begin", "b", "", "Time the entry 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 entry 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(&task, "task", "t", "", "Task to be assigned")
|
finishCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
var trackCmd = &cobra.Command{
|
var trackCmd = &cobra.Command{
|
||||||
Use: "track",
|
Use: "track",
|
||||||
Short: "Tracking time",
|
Short: "Tracking time",
|
||||||
Long: "Add a new tracking entry, which can either be kept running until 'finish' is being called or parameterized to be a finished entry.",
|
Long: "Track new activity, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
user := GetCurrentUser()
|
user := GetCurrentUser()
|
||||||
|
|
||||||
|
@ -38,15 +38,15 @@ var trackCmd = &cobra.Command{
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf(newEntry.GetOutputForTrack(isRunning))
|
fmt.Printf(newEntry.GetOutputForTrack(isRunning, false))
|
||||||
return
|
return
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(trackCmd)
|
rootCmd.AddCommand(trackCmd)
|
||||||
trackCmd.Flags().StringVarP(&begin, "begin", "b", "", "Time the entry 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).")
|
trackCmd.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).")
|
||||||
trackCmd.Flags().StringVarP(&finish, "finish", "s", "", "Time the entry 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.")
|
trackCmd.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.")
|
||||||
trackCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be assigned")
|
trackCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be assigned")
|
||||||
trackCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
|
trackCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
|
||||||
trackCmd.Flags().BoolVarP(&force, "force", "f", false, "Force begin tracking of a new task \neven though another one is still running \n(ONLY IF YOU KNOW WHAT YOU'RE DOING!)")
|
trackCmd.Flags().BoolVarP(&force, "force", "f", false, "Force begin tracking of a new task \neven though another one is still running \n(ONLY IF YOU KNOW WHAT YOU'RE DOING!)")
|
||||||
|
|
Loading…
Reference in a new issue