-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_get.go
63 lines (55 loc) · 1.3 KB
/
cmd_get.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
60
61
62
63
package cmcm
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
)
func newGetCmd() *cobra.Command {
var (
repository string
output string
)
getCmd := &cobra.Command{
Use: "get <comment_id> [flags]",
Short: "Get a commit comment by id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
outputFormat, err := ParseOutputFormat(output)
if err != nil {
return err
}
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
}
cmt, err := commenter.Get(id)
if err != nil {
return err
}
if outputFormat == JSON {
if err := printJSON(cmd.OutOrStdout(), cmt); err != nil {
return err
}
} else {
if err := printPlain(cmd.OutOrStdout(), cmt); err != nil {
return err
}
}
return nil
},
}
getCmd.Flags().StringVarP(&repository, "repo", "R", "", "Select another repository using the OWNER/REPO format")
getCmd.Flags().StringVarP(&output, "output", "o", string(Plain), "Output format. plain or json")
return getCmd
}