added drone repos
command to list repositories via cli
This commit is contained in:
parent
7ba55e5ed7
commit
88c15ecc8e
3 changed files with 46 additions and 1 deletions
|
@ -33,6 +33,7 @@ func main() {
|
|||
|
||||
app.Commands = []cli.Command{
|
||||
NewBuildCommand(),
|
||||
NewReposCommand(),
|
||||
NewEnableCommand(),
|
||||
NewDisableCommand(),
|
||||
NewRestartCommand(),
|
||||
|
|
43
cmd/repos.go
Normal file
43
cmd/repos.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue