harness-drone/cmd/restart.go

41 lines
820 B
Go
Raw Normal View History

2014-07-16 07:34:23 +00:00
package main
import (
"fmt"
"github.com/codegangsta/cli"
)
// NewRestartCommand returns the CLI command for "restart".
func NewRestartCommand() cli.Command {
return cli.Command{
Name: "restart",
2014-08-08 05:22:04 +00:00
Usage: "restarts a build on the server",
2014-07-16 07:34:23 +00:00
Flags: []cli.Flag{},
Action: func(c *cli.Context) {
handle(c, restartCommandFunc)
},
}
}
// restartCommandFunc executes the "restart" command.
func restartCommandFunc(c *cli.Context, client *Client) error {
var branch string = "master"
var commit string
var repo string
var arg = c.Args()
switch len(arg) {
case 2:
repo = arg[0]
commit = arg[1]
case 3:
repo = arg[0]
branch = arg[1]
commit = arg[2]
}
path := fmt.Sprintf("/v1/repos/%s/branches/%s/commits/%s?action=rebuild", repo, branch, commit)
return client.Do("POST", path, nil, nil)
}