2022-01-19 18:56:31 +00:00
|
|
|
/*
|
2022-01-19 21:30:30 +00:00
|
|
|
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
2022-01-19 18:56:31 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.bullercodeworks.com/brian/gime/cli"
|
|
|
|
"git.bullercodeworks.com/brian/gime/util"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// statusCmd represents the status command
|
|
|
|
var statusCmd = &cobra.Command{
|
|
|
|
Use: "status",
|
|
|
|
Short: "Prints the status of all active timers",
|
|
|
|
RunE: opStatus,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(statusCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func opStatus(cmd *cobra.Command, args []string) error {
|
|
|
|
var err error
|
|
|
|
p := cli.Program{}
|
|
|
|
err = p.Initialize()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := p.LoadTimerList(); err != nil {
|
2022-01-21 14:40:44 +00:00
|
|
|
return fmt.Errorf("Error loading timer list: %w", err)
|
2022-01-19 18:56:31 +00:00
|
|
|
}
|
2023-01-12 12:04:17 +00:00
|
|
|
active := p.TimerList.GetActiveTimers().GetTimerSlice()
|
|
|
|
if len(active) == 0 {
|
2022-01-19 18:56:31 +00:00
|
|
|
fmt.Println("No timers running")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var currDur time.Duration
|
2023-01-12 12:04:17 +00:00
|
|
|
for _, v := range active {
|
2022-01-19 18:56:31 +00:00
|
|
|
if v.ActiveToday() {
|
|
|
|
currDur += v.Duration()
|
|
|
|
}
|
|
|
|
}
|
2022-10-04 17:37:11 +00:00
|
|
|
d := util.Round(currDur)
|
|
|
|
|
2022-01-19 18:56:31 +00:00
|
|
|
fmt.Printf("%s ( %.2f hrs )\n", time.Now().Format(time.Stamp), util.DurationToDecimal(d))
|
2023-01-12 12:04:17 +00:00
|
|
|
for _, v := range active {
|
2022-01-19 18:56:31 +00:00
|
|
|
fmt.Println(util.TimerToFriendlyString(v))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|