1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/cli/handle.go

33 lines
668 B
Go
Raw Normal View History

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