-
Notifications
You must be signed in to change notification settings - Fork 23
/
add.go
35 lines (28 loc) 路 757 Bytes
/
add.go
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
package cmd
import (
"strconv"
"github.com/f01c33/clx/favorites"
"github.com/f01c33/clx/hn/services/hybrid"
"github.com/spf13/cobra"
)
func addCmd() *cobra.Command {
return &cobra.Command{
Use: "add",
Short: "Add item to list of favorites by ID",
Long: "Add item to list of favorites by ID",
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
id, err := strconv.Atoi(args[0])
if err != nil {
panic("ID format error")
}
service := hybrid.Service{}
submission := service.FetchItem(id)
fav := favorites.New()
fav.Add(submission)
fav.Write()
println("Item added to favorites")
},
}
}