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
|
|
|
}
|
|
|
|
if len(*p.TimerList.GetActiveTimers()) == 0 {
|
|
|
|
fmt.Println("No timers running")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var currDur time.Duration
|
|
|
|
for _, v := range *p.TimerList {
|
|
|
|
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))
|
|
|
|
for _, v := range *p.TimerList.GetActiveTimers() {
|
|
|
|
fmt.Println(util.TimerToFriendlyString(v))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|