diff --git a/cmd/main.go b/cmd/main.go index f8fd15697..1902436f8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,6 +33,7 @@ func main() { app.Commands = []cli.Command{ NewBuildCommand(), + NewReposCommand(), NewEnableCommand(), NewDisableCommand(), NewRestartCommand(), diff --git a/cmd/repos.go b/cmd/repos.go new file mode 100644 index 000000000..8c5761dbd --- /dev/null +++ b/cmd/repos.go @@ -0,0 +1,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 +} diff --git a/cmd/whoami.go b/cmd/whoami.go index 3b96301dd..7bff13da3 100644 --- a/cmd/whoami.go +++ b/cmd/whoami.go @@ -19,7 +19,8 @@ func NewWhoamiCommand() cli.Command { } } -// whoamiCommandFunc executes the "logout" command. +// whoamiCommandFunc communicates with the server and echoes +// the currently authenticated user. func whoamiCommandFunc(c *cli.Context, client *client.Client) error { user, err := client.Users.GetCurrent() if err != nil {