-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_update.go
59 lines (51 loc) · 1.25 KB
/
cmd_update.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
50
51
52
53
54
55
56
57
58
59
package cmcm
import (
"errors"
"fmt"
"strconv"
"github.com/spf13/cobra"
)
func newUpdateCmd() (*cobra.Command, error) {
var (
repository string
body string
)
updateCmd := &cobra.Command{
Use: "update <comment_id> [flags]",
Short: "Update a commit comment",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if body == "" {
return errors.New("body must not be blank")
}
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])
}
commenter, err := newCommenter(&config{
owner: owner,
repo: repo,
})
if err != nil {
return err
}
url, err := commenter.Update(id, body)
if err != nil {
return err
}
cmd.Println("Comment updated.")
cmd.Println("URL: ", url)
return nil
},
}
updateCmd.Flags().StringVarP(&repository, "repo", "R", "", "Select another repository using the OWNER/REPO format")
updateCmd.Flags().StringVarP(&body, "body", "b", "", "Content of the commit comment")
if err := updateCmd.MarkFlagRequired("body"); err != nil {
return nil, err
}
return updateCmd, nil
}