harness-drone/drone/repo/repo_info.go

58 lines
987 B
Go
Raw Normal View History

2017-04-29 17:03:45 +00:00
package repo
import (
"os"
"text/template"
2017-04-29 17:03:45 +00:00
"github.com/drone/drone/drone/internal"
2017-03-16 10:14:02 +00:00
"github.com/urfave/cli"
)
var repoInfoCmd = cli.Command{
2017-03-16 10:14:02 +00:00
Name: "info",
Usage: "show repository details",
Action: repoInfo,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplRepoInfo,
},
},
}
func repoInfo(c *cli.Context) error {
arg := c.Args().First()
2017-04-29 17:03:45 +00:00
owner, name, err := internal.ParseRepo(arg)
if err != nil {
return err
}
2017-04-29 17:03:45 +00:00
client, err := internal.NewClient(c)
if err != nil {
return err
}
repo, err := client.Repo(owner, name)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format"))
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, repo)
}
// template for repo information
var tmplRepoInfo = `Owner: {{ .Owner }}
Repo: {{ .Name }}
Type: {{ .Kind }}
Config: {{ .Config }}
Private: {{ .IsPrivate }}
Trusted: {{ .IsTrusted }}
Gated: {{ .IsGated }}
Remote: {{ .Clone }}
`