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"
|
|
|
|
|
2022-01-20 14:51:39 +00:00
|
|
|
"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",
|
2022-01-20 14:51:39 +00:00
|
|
|
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 {
|
2022-01-20 14:51:39 +00:00
|
|
|
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
|
|
|
}
|