-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_list.go
63 lines (54 loc) · 1.36 KB
/
cmd_list.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 (
"context"
"github.com/spf13/cobra"
)
func newListCmd() *cobra.Command {
var (
repository string
output string
perPage int
)
listCmd := &cobra.Command{
Use: "list <commit_sha> [flags]",
Short: "List comments of a commit",
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
}
ctx := context.Background()
commenter, err := newCommenter(ctx, &config{
owner: owner,
repo: repo,
})
if err != nil {
return err
}
sha := args[0]
comments, err := commenter.List(ctx, sha, perPage)
if err != nil {
return err
}
if outputFormat == JSON {
if err := printJSON(cmd.OutOrStdout(), comments...); err != nil {
return err
}
} else {
if err := printPlain(cmd.OutOrStdout(), comments...); err != nil {
return err
}
}
return nil
},
}
listCmd.Flags().StringVarP(&repository, "repo", "R", "", "Select another repository using the OWNER/REPO format")
listCmd.Flags().IntVarP(&perPage, "per-page", "", 30, "The number of results per page (max 100)")
listCmd.Flags().StringVarP(&output, "output", "o", string(Plain), "Output format. plain or json")
return listCmd
}