gime/cmd/archive.go

50 lines
942 B
Go
Raw Normal View History

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"
"git.bullercodeworks.com/brian/gime/cli"
"git.bullercodeworks.com/brian/gime/util"
2022-01-19 18:56:31 +00:00
"github.com/spf13/cobra"
)
// archiveCmd represents the archive command
var archiveCmd = &cobra.Command{
Use: "archive",
Short: "Archive timers to the done file",
RunE: opArchive,
2022-01-19 18:56:31 +00:00
}
func init() {
rootCmd.AddCommand(archiveCmd)
2022-01-19 21:30:30 +00:00
}
2022-01-19 18:56:31 +00:00
2022-01-19 21:30:30 +00:00
func opArchive(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
}
filter := util.BuildFilterFromArgs(args)
list := p.TimerList.Filter(filter)
for _, v := range list.GetTimerSlice() {
if v.Finished {
if err := p.ArchiveTimer(v); err != nil {
return fmt.Errorf("Error archiving task %d: %w", v.Id, err)
}
fmt.Println(p.GetDoneTimerString(v))
}
}
2022-01-19 21:30:30 +00:00
return nil
2022-01-19 18:56:31 +00:00
}