blob: 8ec2a118abbc74555655f663fcfd76170076431a (
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
44
45
46
47
48
49
|
package cmd
import (
"strconv"
"strings"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/neonxp/track/internal/tracker"
)
// 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:], " ")
fs := afero.NewOsFs()
tr, err := tracker.New(fs)
if err != nil {
cmd.PrintErr(err)
return
}
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)
}
|