forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos.go
43 lines (37 loc) · 819 Bytes
/
repos.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
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/drone/drone/client"
)
// NewReposCommand returns the CLI command for "repos".
func NewReposCommand() cli.Command {
return cli.Command{
Name: "repos",
Usage: "lists active remote repositories",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "a, all",
Usage: "list all repositories",
},
},
Action: func(c *cli.Context) {
handle(c, reposCommandFunc)
},
}
}
// reposCommandFunc executes the "repos" command.
func reposCommandFunc(c *cli.Context, client *client.Client) error {
repos, err := client.Repos.List()
if err != nil {
return err
}
var all = c.Bool("a")
for _, repo := range repos {
if !all && !repo.Active {
continue
}
fmt.Printf("%s/%s/%s\n", repo.Host, repo.Owner, repo.Name)
}
return nil
}