blob: f1e95701f55eff8e545cae9c46048a8db32288f5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package cmd
import (
"strconv"
"github.com/spf13/cobra"
"github.com/neonxp/track/internal/tracker"
)
// stopCmd represents the stop command
var stopCmd = &cobra.Command{
Use: "stop",
Short: "Stop activity",
Long: `Stop working on activity`,
Run: func(cmd *cobra.Command, args []string) {
activities := tr.List(false)
if len(args) != 0 {
id, err := strconv.Atoi(args[0])
if err != nil {
cmd.PrintErr("First argument must be activity id, got %s.\n", args[0])
return
}
activities = []*tracker.Activity{tr.Activity(id)}
}
for _, activity := range activities {
if err := tr.Stop(activity.ID); err != nil {
cmd.PrintErr(err)
return
}
cmd.Printf(
"Stopped activity \"%s\".\nLast duration: %s.\nAll spent time: %s.\n",
activity.Title,
tracker.Timespan(activity.LastDuration()).Format(),
tracker.Timespan(activity.Duration()).Format(),
)
}
},
}
func init() {
rootCmd.AddCommand(stopCmd)
}
|