mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-19 15:06:34 +00:00
30 lines
587 B
Go
30 lines
587 B
Go
|
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)
|
||
|
}
|
||
|
}
|