aboutsummaryrefslogtreecommitdiff
path: root/cmd/stop.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-12-05 17:46:53 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2021-12-05 17:46:53 +0300
commitbcdbe68ecde049ef62343584bcc26840322c4864 (patch)
tree4a02b4da5db29ab3f3526ff475db859293a97646 /cmd/stop.go
Initial commit
Diffstat (limited to 'cmd/stop.go')
-rw-r--r--cmd/stop.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/stop.go b/cmd/stop.go
new file mode 100644
index 0000000..ac472cd
--- /dev/null
+++ b/cmd/stop.go
@@ -0,0 +1,38 @@
+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\".\n", activity.Title)
+ }
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(stopCmd)
+}