mirror of
https://github.com/drone/drone-cli.git
synced 2024-11-23 01:11:57 +01:00
8f2d7829e3
* Update the way namespace is sent to the drone server. * update drone-go version * bump drone-go library
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package template
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"strings"
|
|
|
|
"github.com/drone/drone-cli/drone/internal"
|
|
"github.com/drone/drone-go/drone"
|
|
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var templateUpdateCmd = cli.Command{
|
|
Name: "update",
|
|
Usage: "update a template",
|
|
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",
|
|
},
|
|
},
|
|
}
|
|
|
|
func templateUpdate(c *cli.Context) error {
|
|
client, err := internal.NewClient(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
namespace := c.String("namespace")
|
|
if namespace == "" {
|
|
return errors.New("missing namespace")
|
|
}
|
|
|
|
template := &drone.Template{
|
|
Name: c.String("name"),
|
|
}
|
|
if strings.HasPrefix(c.String("data"), "@") {
|
|
path := strings.TrimPrefix(c.String("data"), "@")
|
|
out, ferr := ioutil.ReadFile(path)
|
|
if ferr != nil {
|
|
return ferr
|
|
}
|
|
template.Data = string(out)
|
|
}
|
|
_, err = client.TemplateUpdate(namespace, template.Name, template)
|
|
return err
|
|
}
|