harness-drone/cmd/handle.go

33 lines
668 B
Go
Raw Normal View History

2014-07-16 07:34:23 +00:00
package main
import (
"os"
"github.com/codegangsta/cli"
2014-08-09 23:51:08 +00:00
"github.com/drone/drone/client"
2014-07-16 07:34:23 +00:00
)
2014-08-09 23:51:08 +00:00
type handlerFunc func(*cli.Context, *client.Client) error
2014-07-16 07:34:23 +00:00
// handle wraps the command function handlers and
// sets up the environment.
func handle(c *cli.Context, fn handlerFunc) {
2014-08-09 23:51:08 +00:00
var token = c.GlobalString("token")
var server = c.GlobalString("server")
2014-07-16 07:34:23 +00:00
2014-08-09 23:51:08 +00:00
// if no server url is provided we can default
2014-07-16 07:34:23 +00:00
// to the hosted Drone service.
2014-08-09 23:51:08 +00:00
if len(server) == 0 {
server = "http://test.drone.io"
2014-07-16 07:34:23 +00:00
}
2014-08-09 23:51:08 +00:00
// create the drone client
client := client.New(token, server)
2014-07-16 07:34:23 +00:00
// handle the function
2014-08-09 23:51:08 +00:00
if err := fn(c, client); err != nil {
2014-07-16 07:34:23 +00:00
println(err.Error())
os.Exit(1)
}
}