diff --git a/cmd/helm.go b/cmd/helm.go index 946b67eb7..e044b8be8 100644 --- a/cmd/helm.go +++ b/cmd/helm.go @@ -17,6 +17,16 @@ func main() { app.Usage = `Deploy and manage packages.` app.Commands = commands() + // TODO: make better + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "host,u", + Usage: "The URL of the DM server.", + EnvVar: "HELM_HOST", + Value: "https://localhost:8181/FIXME_NOT_RIGHT", + }, + } + app.Run(os.Args) } @@ -89,7 +99,7 @@ func commands() []cli.Command { d.Input = os.Stdin } - if err := deploy(d, c.String("host"), c.Bool("dry-run")); err != nil { + if err := deploy(d, c.GlobalString("host"), c.Bool("dry-run")); err != nil { format.Error("%s (Try running 'helm doctor')", err) os.Exit(1) } @@ -119,16 +129,11 @@ func commands() []cli.Command { Usage: "The default repository", Value: "kubernetes/application-dm-templates", }, - cli.StringFlag{ - Name: "host,u", - Usage: "The URL of the DM server.", - EnvVar: "HELM_HOST", - Value: "https://localhost:8181/FIXME_NOT_RIGHT", - }, }, }, { Name: "search", }, + listCmd(), } } diff --git a/cmd/list.go b/cmd/list.go new file mode 100644 index 000000000..b5eb7446d --- /dev/null +++ b/cmd/list.go @@ -0,0 +1,28 @@ +package main + +import ( + "os" + + "github.com/codegangsta/cli" + "github.com/deis/helm-dm/dm" + "github.com/deis/helm-dm/format" +) + +func listCmd() cli.Command { + return cli.Command{ + Name: "list", + Usage: "Lists the deployments in the cluster", + Action: func(c *cli.Context) { + if err := list(c.GlobalString("host")); err != nil { + format.Error("%s (Is the cluster running?)", err) + os.Exit(1) + } + }, + } +} + +func list(host string) error { + client := dm.NewClient(host) + client.Protocol = "http" + return client.ListDeployments() +} diff --git a/dm/client.go b/dm/client.go index 303f17a40..27a01c203 100644 --- a/dm/client.go +++ b/dm/client.go @@ -96,3 +96,13 @@ func (c *Client) callHttp(path, method, action string, reader io.ReadCloser) (st return string(body), nil } + +func (c *Client) ListDeployments() error { + var d interface{} + if err := c.CallService("deployments", "GET", "foo", &d, nil); err != nil { + return err + } + + fmt.Printf("%#v\n", d) + return nil +}