gime/cmd/status.go
2022-01-19 12:56:31 -06:00

54 lines
1.1 KiB
Go

/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
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 err
}
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()
}
}
d := currDur.Round(util.GetRoundToDuration())
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
}