/
list.go
53 lines (49 loc) · 991 Bytes
/
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
package main
import (
"fmt"
"path"
"github.com/codegangsta/cli"
"github.com/lgtmco/lgtm-go/lgtm"
)
var ListCmd = cli.Command{
Name: "ls",
Usage: "list repositories",
Action: func(c *cli.Context) {
handle(c, listCmd)
},
Flags: []cli.Flag{
cli.BoolTFlag{
Name: "active",
Usage: "list active repositories",
},
cli.BoolFlag{
Name: "inactive",
Usage: "list inactive repositories",
},
cli.StringFlag{
Name: "exclude",
Usage: "exclude repositories matching the pattern",
},
},
}
func listCmd(c *cli.Context, client lgtm.Client) error {
var (
active = c.BoolT("active")
inactive = c.Bool("inactive")
exclude = c.String("exclude")
)
repos, err := client.Repos()
if err != nil {
return err
}
for _, repo := range repos {
match, _ := path.Match(exclude, repo.Slug)
switch {
case !match && active && repo.ID != 0:
fmt.Println(repo.Slug)
case !match && inactive && repo.ID == 0:
fmt.Println(repo.Slug)
}
}
return nil
}