diff --git a/cmd/helm/get.go b/cmd/helm/get.go index e5dcfe921..4fd0d5c5e 100644 --- a/cmd/helm/get.go +++ b/cmd/helm/get.go @@ -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 } diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index b84d03fbc..268498ea6 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -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) +} diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 24f200a5b..70d2abb30 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -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 } diff --git a/dm/client.go b/dm/client.go index fbc6b46f4..b95a59356 100644 --- a/dm/client.go +++ b/dm/client.go @@ -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)