-
Notifications
You must be signed in to change notification settings - Fork 180
/
build_promote.go
59 lines (52 loc) · 1.2 KB
/
build_promote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package build
import (
"os"
"strconv"
"text/template"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/funcmap"
"github.com/urfave/cli"
)
var buildPromoteCmd = cli.Command{
Name: "promote",
Usage: "promote a build",
ArgsUsage: "<repo/name> <build> <environment>",
Action: buildPromote,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "param, p",
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
},
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplBuildInfo,
},
},
}
func buildPromote(c *cli.Context) (err error) {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
number, err := strconv.Atoi(c.Args().Get(1))
if err != nil {
return err
}
target := c.Args().Get(2)
params := internal.ParseKeyPair(c.StringSlice("param"))
client, err := internal.NewClient(c)
if err != nil {
return err
}
build, err := client.Promote(owner, name, number, target, params)
if err != nil {
return err
}
tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format"))
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, build)
}