mirror of
https://github.com/drone/drone-cli.git
synced 2024-11-23 01:11:57 +01:00
Add support for organization level templates
This commit is contained in:
parent
8d1b7ef711
commit
b5490cd67e
@ -1,6 +1,7 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/drone/drone-cli/drone/internal"
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/urfave/cli"
|
||||
@ -11,13 +12,17 @@ import (
|
||||
var templateCreateCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "adds a template",
|
||||
ArgsUsage: "[name]",
|
||||
ArgsUsage: "[namespace] [name] [data]",
|
||||
Action: templateCreate,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "template name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "namespace",
|
||||
Usage: "organization namespace",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "data",
|
||||
Usage: "template file data",
|
||||
@ -31,7 +36,15 @@ func templateCreate(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
template := &drone.Template{
|
||||
Name: c.String("name"),
|
||||
Namespace: c.String("namespace"),
|
||||
Name: c.String("name"),
|
||||
}
|
||||
|
||||
if template.Name == "" {
|
||||
return errors.New("Missing template name")
|
||||
}
|
||||
if template.Namespace == "" {
|
||||
return errors.New("Missing namespace")
|
||||
}
|
||||
|
||||
if strings.HasPrefix(c.String("data"), "@") {
|
||||
@ -40,7 +53,7 @@ func templateCreate(c *cli.Context) error {
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
template.Data = out
|
||||
template.Data = string(out)
|
||||
}
|
||||
_, err = client.TemplateCreate(template)
|
||||
return err
|
||||
|
@ -13,9 +13,13 @@ import (
|
||||
var templateInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "display template info",
|
||||
ArgsUsage: "[name]",
|
||||
ArgsUsage: "[namespace] [name]",
|
||||
Action: templateInfo,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "namespace",
|
||||
Usage: "organization namespace",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "template name",
|
||||
@ -30,18 +34,22 @@ var templateInfoCmd = cli.Command{
|
||||
|
||||
func templateInfo(c *cli.Context) error {
|
||||
var (
|
||||
namespace = c.String("namespace")
|
||||
templateName = c.String("name")
|
||||
format = c.String("format") + "\n"
|
||||
)
|
||||
if templateName == "" {
|
||||
return errors.New("Missing template name")
|
||||
}
|
||||
if namespace == "" {
|
||||
return errors.New("Missing namespace")
|
||||
}
|
||||
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
templates, err := client.Template(templateName)
|
||||
templates, err := client.Template(namespace, templateName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -52,6 +60,6 @@ func templateInfo(c *cli.Context) error {
|
||||
return tmpl.Execute(os.Stdout, templates)
|
||||
}
|
||||
|
||||
var tmplTemplateInfoList = "\x1b[33m{{ .Name }} \x1b[0m" + `
|
||||
var tmplTemplateInfoList = "\x1b[33m{{ .Name }} \x1b[0m" + "\x1b [33m{{ .Namespace }} \x1b[0m" + `
|
||||
Data: {{ .Data }}
|
||||
`
|
||||
|
@ -24,13 +24,14 @@ var templateListCmd = cli.Command{
|
||||
|
||||
func templateList(c *cli.Context) error {
|
||||
var (
|
||||
format = c.String("format") + "\n"
|
||||
namespace = c.Args().First()
|
||||
format = c.String("format") + "\n"
|
||||
)
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
list, err := client.TemplateList()
|
||||
list, err := client.TemplateList(namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -8,23 +8,28 @@ import (
|
||||
var templateDeleteCmd = cli.Command{
|
||||
Name: "rm",
|
||||
Usage: "remove a template",
|
||||
ArgsUsage: "[name]",
|
||||
ArgsUsage: "[namespace] [name]",
|
||||
Action: templateDelete,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "template name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "namespace",
|
||||
Usage: "organization name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func templateDelete(c *cli.Context) error {
|
||||
var (
|
||||
name = c.String("name")
|
||||
namespace = c.String("namespace")
|
||||
name = c.String("name")
|
||||
)
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.TemplateDelete(name)
|
||||
return client.TemplateDelete(namespace, name)
|
||||
}
|
||||
|
@ -11,13 +11,17 @@ import (
|
||||
var templateUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "update a template",
|
||||
ArgsUsage: "[name]",
|
||||
ArgsUsage: "[namespace] [name] [data]",
|
||||
Action: templateUpdate,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "template name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "namespace",
|
||||
Usage: "organization name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "data",
|
||||
Usage: "template file data",
|
||||
@ -31,7 +35,8 @@ func templateUpdate(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
template := &drone.Template{
|
||||
Name: c.String("name"),
|
||||
Name: c.String("name"),
|
||||
Namespace: c.String("namespace"),
|
||||
}
|
||||
if strings.HasPrefix(c.String("data"), "@") {
|
||||
path := strings.TrimPrefix(c.String("data"), "@")
|
||||
@ -39,8 +44,8 @@ func templateUpdate(c *cli.Context) error {
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
template.Data = out
|
||||
template.Data = string(out)
|
||||
}
|
||||
_, err = client.TemplateUpdate(template.Name, template)
|
||||
_, err = client.TemplateUpdate(template.Namespace, template.Name, template)
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user