Commit 6058cad0 authored by Adam Reese's avatar Adam Reese

feat(client): add timeout cli option

parent 8cf1f350
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"errors" "errors"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
) )
...@@ -22,10 +21,7 @@ func get(c *cli.Context) error { ...@@ -22,10 +21,7 @@ func get(c *cli.Context) error {
return errors.New("First argument, deployment name, is required. Try 'helm get --help'") return errors.New("First argument, deployment name, is required. Try 'helm get --help'")
} }
name := args[0] name := args[0]
host := c.GlobalString("host") deployment, err := client(c).GetDeployment(name)
client := dm.NewClient(host).SetDebug(c.GlobalBool("debug"))
deployment, err := client.GetDeployment(name)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"os" "os"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
) )
...@@ -24,6 +25,11 @@ func main() { ...@@ -24,6 +25,11 @@ func main() {
EnvVar: "HELM_HOST", EnvVar: "HELM_HOST",
Value: "https://localhost:8181/FIXME_NOT_RIGHT", Value: "https://localhost:8181/FIXME_NOT_RIGHT",
}, },
cli.IntFlag{
Name: "timeout",
Usage: "Time in seconds to wait for response",
Value: 10,
},
cli.BoolFlag{ cli.BoolFlag{
Name: "debug", Name: "debug",
Usage: "Enable verbose debugging output", Usage: "Enable verbose debugging output",
...@@ -184,3 +190,10 @@ func run(c *cli.Context, f func(c *cli.Context) error) { ...@@ -184,3 +190,10 @@ func run(c *cli.Context, f func(c *cli.Context) error) {
os.Exit(1) 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 ...@@ -2,7 +2,6 @@ package main
import ( import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
) )
...@@ -15,9 +14,7 @@ func listCmd() cli.Command { ...@@ -15,9 +14,7 @@ func listCmd() cli.Command {
} }
func list(c *cli.Context) error { func list(c *cli.Context) error {
host := c.GlobalString("host") list, err := client(c).ListDeployments()
client := dm.NewClient(host).SetDebug(c.GlobalBool("debug"))
list, err := client.ListDeployments()
if err != nil { if err != nil {
return err return err
} }
......
...@@ -69,6 +69,12 @@ func (c *Client) SetTransport(tr http.RoundTripper) *Client { ...@@ -69,6 +69,12 @@ func (c *Client) SetTransport(tr http.RoundTripper) *Client {
return c 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. // url constructs the URL.
func (c *Client) url(rawurl string) (string, error) { func (c *Client) url(rawurl string) (string, error) {
u, err := url.Parse(rawurl) u, err := url.Parse(rawurl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment