aboutsummaryrefslogtreecommitdiff
path: root/cmd/start.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/start.go')
-rw-r--r--cmd/start.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/start.go b/cmd/start.go
new file mode 100644
index 0000000..a0ae4f1
--- /dev/null
+++ b/cmd/start.go
@@ -0,0 +1,37 @@
+package cmd
+
+import (
+ "strconv"
+ "strings"
+
+ "github.com/spf13/cobra"
+)
+
+// startCmd represents the start command
+var startCmd = &cobra.Command{
+ Use: "start",
+ Short: "Start activity",
+ Long: `Start new timespan on activity`,
+ Run: func(cmd *cobra.Command, args []string) {
+ if len(args) == 0 {
+ cmd.PrintErr("First argument must be activity id\n")
+ return
+ }
+ id, err := strconv.Atoi(args[0])
+ if err != nil {
+ cmd.PrintErr("First argument must be activity id, got %s\n", args[0])
+ return
+ }
+ comment := strings.Join(args[1:], " ")
+ if err := tr.Start(id, comment); err != nil {
+ cmd.PrintErr(err)
+ return
+ }
+ activity := tr.Activity(id)
+ cmd.Printf("Started new span for activity \"%s\".\n", activity.Title)
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(startCmd)
+}