forked from zaquestion/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippetDelete.go
49 lines (44 loc) · 1000 Bytes
/
snippetDelete.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"log"
"github.com/spf13/cobra"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
)
// snippetDeleteCmd represents the snippetDelete command
var snippetDeleteCmd = &cobra.Command{
Use: "delete [remote] <id>",
Short: "Delete a project or personal snippet",
Long: ``,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
remote, id, err := parseArgsRemote(args)
if err != nil {
log.Fatal(err)
}
if remote == "" {
remote = forkedFromRemote
}
rn, _ := git.PathWithNameSpace(remote)
if global || rn == "" {
err = lab.SnippetDelete(int(id))
if err != nil {
log.Fatal(err)
}
fmt.Printf("Snippet #%d deleted\n", id)
return
}
project, err := lab.FindProject(rn)
if err != nil {
log.Fatal(err)
}
err = lab.ProjectSnippetDelete(project.ID, int(id))
if err != nil {
log.Fatal(err)
}
},
}
func init() {
snippetCmd.AddCommand(snippetDeleteCmd)
}