1
0
mirror of https://github.com/drone/drone-cli.git synced 2025-07-13 07:34:18 +02:00
drone-cli/drone/repos.go
2015-02-13 00:23:01 -08:00

44 lines
820 B
Go

package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/drone/drone-go/drone"
)
// 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 *drone.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
}