Refactored output
This commit is contained in:
parent
44dd4039fc
commit
f95d4dfbb4
3 changed files with 37 additions and 29 deletions
36
z/entry.go
36
z/entry.go
|
@ -3,6 +3,8 @@ package z
|
|||
import (
|
||||
"errors"
|
||||
"time"
|
||||
"fmt"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
|
@ -80,5 +82,37 @@ func (entry *Entry) SetFinishFromString(finish string) (time.Time, error) {
|
|||
}
|
||||
|
||||
func (entry *Entry) IsFinishedAfterBegan() (bool) {
|
||||
return (entry.Finish.IsZero() == false && entry.Begin.Before(entry.Finish))
|
||||
return (entry.Finish.IsZero() || entry.Begin.Before(entry.Finish))
|
||||
}
|
||||
|
||||
func (entry *Entry) GetOutputForTrack(isRunning bool) (string) {
|
||||
outputPrefix := "began tracking"
|
||||
if isRunning == false {
|
||||
outputPrefix = "tracked"
|
||||
}
|
||||
|
||||
if entry.Task != "" && entry.Project != "" {
|
||||
return fmt.Sprintf("▷ %s %s on %s\n", outputPrefix, color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project))
|
||||
} else if entry.Task != "" && entry.Project == "" {
|
||||
return fmt.Sprintf("▷ %s %s\n", outputPrefix, color.FgLightWhite.Render(entry.Task))
|
||||
} else if entry.Task == "" && entry.Project != "" {
|
||||
return fmt.Sprintf("▷ %s task on %s\n", outputPrefix, color.FgLightWhite.Render(entry.Project))
|
||||
} else {
|
||||
return fmt.Sprintf("▷ %s task\n", outputPrefix)
|
||||
}
|
||||
}
|
||||
|
||||
func (entry *Entry) GetOutputForFinish() (string) {
|
||||
trackDiff := entry.Finish.Sub(entry.Begin)
|
||||
trackDiffOut := time.Time{}.Add(trackDiff)
|
||||
|
||||
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"))
|
||||
} else if entry.Task != "" && entry.Project == "" {
|
||||
return fmt.Sprintf("□ finished tracking %s for %sh\n", color.FgLightWhite.Render(entry.Task), trackDiffOut.Format("15:04"))
|
||||
} 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\n")
|
||||
}
|
||||
|
|
14
z/finish.go
14
z/finish.go
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
var finishCmd = &cobra.Command{
|
||||
|
@ -59,18 +58,7 @@ var finishCmd = &cobra.Command{
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
trackDiff := runningEntry.Finish.Sub(runningEntry.Begin)
|
||||
trackDiffOut := time.Time{}.Add(trackDiff)
|
||||
|
||||
if runningEntry.Task != "" && runningEntry.Project != "" {
|
||||
fmt.Printf("□ finished tracking %s on %s for %sh\n", color.FgLightWhite.Render(runningEntry.Task), color.FgLightWhite.Render(runningEntry.Project), trackDiffOut.Format("15:04"))
|
||||
} else if runningEntry.Task != "" && runningEntry.Project == "" {
|
||||
fmt.Printf("□ finished tracking %s for %sh\n", color.FgLightWhite.Render(runningEntry.Task), trackDiffOut.Format("15:04"))
|
||||
} else if runningEntry.Task == "" && runningEntry.Project != "" {
|
||||
fmt.Printf("□ finished tracking task on %s for %sh\n", color.FgLightWhite.Render(runningEntry.Project), trackDiffOut.Format("15:04"))
|
||||
} else {
|
||||
fmt.Printf("□ finished tracking task\n")
|
||||
}
|
||||
fmt.Printf(runningEntry.GetOutputForFinish())
|
||||
return
|
||||
},
|
||||
}
|
||||
|
|
16
z/track.go
16
z/track.go
|
@ -5,7 +5,6 @@ import (
|
|||
"log"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
var trackCmd = &cobra.Command{
|
||||
|
@ -37,20 +36,7 @@ var trackCmd = &cobra.Command{
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
outputPrefix := "began tracking"
|
||||
if isRunning == false {
|
||||
outputPrefix = "tracked"
|
||||
}
|
||||
|
||||
if newEntry.Task != "" && newEntry.Project != "" {
|
||||
fmt.Printf("▷ %s %s on %s\n", outputPrefix, color.FgLightWhite.Render(newEntry.Task), color.FgLightWhite.Render(newEntry.Project))
|
||||
} else if newEntry.Task != "" && newEntry.Project == "" {
|
||||
fmt.Printf("▷ %s %s\n", outputPrefix, color.FgLightWhite.Render(newEntry.Task))
|
||||
} else if newEntry.Task == "" && newEntry.Project != "" {
|
||||
fmt.Printf("▷ %s task on %s\n", outputPrefix, color.FgLightWhite.Render(newEntry.Project))
|
||||
} else {
|
||||
fmt.Printf("▷ %s task\n", outputPrefix)
|
||||
}
|
||||
fmt.Printf(newEntry.GetOutputForTrack(isRunning))
|
||||
return
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue