feat(client): add timeout cli option

pull/291/head
Adam Reese 9 years ago
parent 8cf1f35059
commit 6058cad0a1

@ -4,7 +4,6 @@ import (
"errors"
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format"
)
@ -22,10 +21,7 @@ func get(c *cli.Context) error {
return errors.New("First argument, deployment name, is required. Try 'helm get --help'")
}
name := args[0]
host := c.GlobalString("host")
client := dm.NewClient(host).SetDebug(c.GlobalBool("debug"))
deployment, err := client.GetDeployment(name)
deployment, err := client(c).GetDeployment(name)
if err != nil {
return err
}

@ -4,6 +4,7 @@ import (
"os"
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format"
)
@ -24,6 +25,11 @@ func main() {
EnvVar: "HELM_HOST",
Value: "https://localhost:8181/FIXME_NOT_RIGHT",
},
cli.IntFlag{
Name: "timeout",
Usage: "Time in seconds to wait for response",
Value: 10,
},
cli.BoolFlag{
Name: "debug",
Usage: "Enable verbose debugging output",
@ -184,3 +190,10 @@ func run(c *cli.Context, f func(c *cli.Context) error) {
os.Exit(1)
}
}
func client(c *cli.Context) *dm.Client {
host := c.GlobalString("host")
debug := c.GlobalBool("debug")
timeout := c.GlobalInt("timeout")
return dm.NewClient(host).SetDebug(debug).SetTimeout(timeout)
}

@ -2,7 +2,6 @@ package main
import (
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format"
)
@ -15,9 +14,7 @@ func listCmd() cli.Command {
}
func list(c *cli.Context) error {
host := c.GlobalString("host")
client := dm.NewClient(host).SetDebug(c.GlobalBool("debug"))
list, err := client.ListDeployments()
list, err := client(c).ListDeployments()
if err != nil {
return err
}

@ -69,6 +69,12 @@ func (c *Client) SetTransport(tr http.RoundTripper) *Client {
return c
}
// SetTimeout sets a timeout for http connections
func (c *Client) SetTimeout(seconds int) *Client {
c.HTTPTimeout = time.Duration(time.Duration(seconds) * time.Second)
return c
}
// url constructs the URL.
func (c *Client) url(rawurl string) (string, error) {
u, err := url.Parse(rawurl)

Loading…
Cancel
Save