mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-26 10:20:29 +00:00
32 lines
668 B
Go
32 lines
668 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/codegangsta/cli"
|
|
"github.com/drone/drone/client"
|
|
)
|
|
|
|
type handlerFunc func(*cli.Context, *client.Client) error
|
|
|
|
// handle wraps the command function handlers and
|
|
// sets up the environment.
|
|
func handle(c *cli.Context, fn handlerFunc) {
|
|
var token = c.GlobalString("token")
|
|
var server = c.GlobalString("server")
|
|
|
|
// if no server url is provided we can default
|
|
// to the hosted Drone service.
|
|
if len(server) == 0 {
|
|
server = "http://test.drone.io"
|
|
}
|
|
|
|
// create the drone client
|
|
client := client.New(token, server)
|
|
|
|
// handle the function
|
|
if err := fn(c, client); err != nil {
|
|
println(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|