gime/cmd/status.go

56 lines
1.1 KiB
Go

/*
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
*/
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 {
return fmt.Errorf("Error loading timer list: %w", err)
}
active := p.TimerList.GetActiveTimers().GetTimerSlice()
if len(active) == 0 {
fmt.Println("No timers running")
return nil
}
var currDur time.Duration
for _, v := range active {
if v.ActiveToday() {
currDur += v.Duration()
}
}
d := util.Round(currDur)
fmt.Printf("%s ( %.2f hrs )\n", time.Now().Format(time.Stamp), util.DurationToDecimal(d))
for _, v := range active {
fmt.Println(util.TimerToFriendlyString(v))
}
return nil
}