/
cmd_delete.go
49 lines (42 loc) · 1000 Bytes
/
cmd_delete.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 cmcm
import (
"context"
"fmt"
"strconv"
"github.com/spf13/cobra"
)
func newDeleteCmd() *cobra.Command {
var (
repository string
)
deleteCmd := &cobra.Command{
Use: "delete <commit_id> [flags]",
Short: "Delete a commit comment",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
owner, repo, err := parseRepository(repository)
if err != nil {
return err
}
id, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return fmt.Errorf("failed to parse arg to integer: %s", args[0])
}
ctx := context.Background()
commenter, err := newCommenter(ctx, &config{
owner: owner,
repo: repo,
})
if err != nil {
return err
}
if err := commenter.Delete(ctx, id); err != nil {
return err
}
cmd.Println("Comment deleted.")
return nil
},
}
deleteCmd.Flags().StringVarP(&repository, "repo", "R", "", "Select another repository using the OWNER/REPO format")
return deleteCmd
}