woodpecker/client/command/handle.go

30 lines
587 B
Go
Raw Normal View History

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