2019-04-06 21:32:14 +02:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-10-12 09:25:13 +02:00
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
2021-09-21 16:36:41 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
2019-04-06 21:32:14 +02:00
|
|
|
)
|
|
|
|
|
2021-10-27 21:03:14 +02:00
|
|
|
var repoListCmd = &cli.Command{
|
2019-04-06 21:32:14 +02:00
|
|
|
Name: "ls",
|
|
|
|
Usage: "list all repos",
|
|
|
|
ArgsUsage: " ",
|
|
|
|
Action: repoList,
|
2021-10-27 21:03:14 +02:00
|
|
|
Flags: append(common.GlobalFlags,
|
|
|
|
common.FormatFlag(tmplRepoList),
|
|
|
|
&cli.StringFlag{
|
2019-04-06 21:32:14 +02:00
|
|
|
Name: "org",
|
|
|
|
Usage: "filter by organization",
|
|
|
|
},
|
2021-10-27 21:03:14 +02:00
|
|
|
),
|
2019-04-06 21:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func repoList(c *cli.Context) error {
|
|
|
|
client, err := internal.NewClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
repos, err := client.RepoList()
|
|
|
|
if err != nil || len(repos) == 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
org := c.String("org")
|
|
|
|
for _, repo := range repos {
|
|
|
|
if org != "" && org != repo.Owner {
|
|
|
|
continue
|
|
|
|
}
|
2021-11-23 16:36:52 +02:00
|
|
|
if err := tmpl.Execute(os.Stdout, repo); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-04-06 21:32:14 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// template for repository list items
|
|
|
|
var tmplRepoList = `{{ .FullName }}`
|