50 lines
942 B
Go
50 lines
942 B
Go
/*
|
|
Copyright © 2022 Brian Buller <brian@bullercodeworks.com>
|
|
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.bullercodeworks.com/brian/gime/cli"
|
|
"git.bullercodeworks.com/brian/gime/util"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// archiveCmd represents the archive command
|
|
var archiveCmd = &cobra.Command{
|
|
Use: "archive",
|
|
Short: "Archive timers to the done file",
|
|
RunE: opArchive,
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(archiveCmd)
|
|
}
|
|
|
|
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))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|