Commit 3c62cd9f authored by Adam Reese's avatar Adam Reese

ref(cmd): break up command definitions

parent 20d3ea9f
...@@ -7,6 +7,18 @@ import ( ...@@ -7,6 +7,18 @@ import (
"github.com/kubernetes/deployment-manager/chart" "github.com/kubernetes/deployment-manager/chart"
) )
func init() {
addCommands(createCmd())
}
func createCmd() cli.Command {
return cli.Command{
Name: "create",
Usage: "Create a new local chart for editing.",
Action: func(c *cli.Context) { run(c, create) },
}
}
func create(c *cli.Context) error { func create(c *cli.Context) error {
args := c.Args() args := c.Args()
if len(args) < 1 { if len(args) < 1 {
......
...@@ -10,6 +10,45 @@ import ( ...@@ -10,6 +10,45 @@ import (
"github.com/kubernetes/deployment-manager/chart" "github.com/kubernetes/deployment-manager/chart"
) )
func init() {
addCommands(deployCmd())
}
func deployCmd() cli.Command {
return cli.Command{
Name: "deploy",
Aliases: []string{"install"},
Usage: "Deploy a chart into the cluster.",
Action: func(c *cli.Context) { run(c, deploy) },
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Only display the underlying kubectl commands.",
},
cli.BoolFlag{
Name: "stdin,i",
Usage: "Read a configuration from STDIN.",
},
cli.StringFlag{
Name: "name",
Usage: "Name of deployment, used for deploy and update commands (defaults to template name)",
},
// TODO: I think there is a Generic flag type that we can implement parsing with.
cli.StringFlag{
Name: "properties,p",
Usage: "A comma-separated list of key=value pairs: 'foo=bar,foo2=baz'.",
},
cli.StringFlag{
// FIXME: This is not right. It's sort of a half-baked forward
// port of dm.go.
Name: "repository",
Usage: "The default repository",
Value: "kubernetes/application-dm-templates",
},
},
}
}
func deploy(c *cli.Context) error { func deploy(c *cli.Context) error {
args := c.Args() args := c.Args()
if len(args) < 1 { if len(args) < 1 {
......
...@@ -2,7 +2,9 @@ package main ...@@ -2,7 +2,9 @@ package main
import ( import (
"errors" "errors"
"os"
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm" "github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
"github.com/deis/helm-dm/kubectl" "github.com/deis/helm-dm/kubectl"
...@@ -11,6 +13,78 @@ import ( ...@@ -11,6 +13,78 @@ import (
// ErrAlreadyInstalled indicates that DM is already installed. // ErrAlreadyInstalled indicates that DM is already installed.
var ErrAlreadyInstalled = errors.New("Already Installed") var ErrAlreadyInstalled = errors.New("Already Installed")
func init() {
addCommands(dmCmd())
}
func dmCmd() cli.Command {
return cli.Command{
Name: "dm",
Usage: "Manage DM on Kubernetes",
Subcommands: []cli.Command{
{
Name: "install",
Usage: "Install DM on Kubernetes.",
Description: ``,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Show what would be installed, but don't install anything.",
},
},
Action: func(c *cli.Context) {
if err := install(c.Bool("dry-run")); err != nil {
format.Err("%s (Run 'helm doctor' for more information)", err)
os.Exit(1)
}
},
},
{
Name: "uninstall",
Usage: "Uninstall the DM from Kubernetes.",
Description: ``,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Show what would be installed, but don't install anything.",
},
},
Action: func(c *cli.Context) {
if err := uninstall(c.Bool("dry-run")); err != nil {
format.Err("%s (Run 'helm doctor' for more information)", err)
os.Exit(1)
}
},
},
{
Name: "status",
Usage: "Show status of DM.",
Action: func(c *cli.Context) {
format.Err("Not yet implemented")
os.Exit(1)
},
},
{
Name: "target",
Usage: "Displays information about cluster.",
ArgsUsage: "",
Action: func(c *cli.Context) {
if err := target(c.Bool("dry-run")); err != nil {
format.Err("%s (Is the cluster running?)", err)
os.Exit(1)
}
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Only display the underlying kubectl commands.",
},
},
},
},
}
}
func install(dryRun bool) error { func install(dryRun bool) error {
runner := getKubectlRunner(dryRun) runner := getKubectlRunner(dryRun)
......
package main package main
import ( import (
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm" "github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
"github.com/deis/helm-dm/kubectl" "github.com/deis/helm-dm/kubectl"
) )
func doctor() error { func init() {
addCommands(doctorCmd())
}
func doctorCmd() cli.Command {
return cli.Command{
Name: "doctor",
Usage: "Run a series of checks for necessary prerequisites.",
ArgsUsage: "",
Action: func(c *cli.Context) { run(c, doctor) },
}
}
func doctor(c *cli.Context) error {
var runner kubectl.Runner var runner kubectl.Runner
runner = &kubectl.RealRunner{} runner = &kubectl.RealRunner{}
if dm.IsInstalled(runner) { if dm.IsInstalled(runner) {
......
...@@ -7,6 +7,10 @@ import ( ...@@ -7,6 +7,10 @@ import (
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
) )
func init() {
addCommands(getCmd())
}
func getCmd() cli.Command { func getCmd() cli.Command {
return cli.Command{ return cli.Command{
Name: "get", Name: "get",
......
...@@ -10,12 +10,18 @@ import ( ...@@ -10,12 +10,18 @@ import (
var version = "0.0.1" var version = "0.0.1"
var commands []cli.Command
func init() {
commands = cmds()
}
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "helm" app.Name = "helm"
app.Version = version app.Version = version
app.Usage = `Deploy and manage packages.` app.Usage = `Deploy and manage packages.`
app.Commands = commands() app.Commands = commands
// TODO: make better // TODO: make better
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
...@@ -38,73 +44,8 @@ func main() { ...@@ -38,73 +44,8 @@ func main() {
app.Run(os.Args) app.Run(os.Args)
} }
func commands() []cli.Command { func cmds() []cli.Command {
return []cli.Command{ return []cli.Command{
{
Name: "dm",
Usage: "Manage DM on Kubernetes",
Subcommands: []cli.Command{
{
Name: "install",
Usage: "Install DM on Kubernetes.",
Description: ``,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Show what would be installed, but don't install anything.",
},
},
Action: func(c *cli.Context) {
if err := install(c.Bool("dry-run")); err != nil {
format.Err("%s (Run 'helm doctor' for more information)", err)
os.Exit(1)
}
},
},
{
Name: "uninstall",
Usage: "Uninstall the DM from Kubernetes.",
Description: ``,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Show what would be installed, but don't install anything.",
},
},
Action: func(c *cli.Context) {
if err := uninstall(c.Bool("dry-run")); err != nil {
format.Err("%s (Run 'helm doctor' for more information)", err)
os.Exit(1)
}
},
},
{
Name: "status",
Usage: "Show status of DM.",
Action: func(c *cli.Context) {
format.Err("Not yet implemented")
os.Exit(1)
},
},
{
Name: "target",
Usage: "Displays information about cluster.",
ArgsUsage: "",
Action: func(c *cli.Context) {
if err := target(c.Bool("dry-run")); err != nil {
format.Err("%s (Is the cluster running?)", err)
os.Exit(1)
}
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Only display the underlying kubectl commands.",
},
},
},
},
},
{ {
Name: "init", Name: "init",
Usage: "Initialize the client and install DM on Kubernetes.", Usage: "Initialize the client and install DM on Kubernetes.",
...@@ -122,68 +63,16 @@ func commands() []cli.Command { ...@@ -122,68 +63,16 @@ func commands() []cli.Command {
} }
}, },
}, },
{
Name: "doctor",
Usage: "Run a series of checks for necessary prerequisites.",
ArgsUsage: "",
Action: func(c *cli.Context) {
if err := doctor(); err != nil {
format.Err("%s", err)
os.Exit(1)
}
},
},
{
Name: "create",
Usage: "Create a new local chart for editing.",
Action: func(c *cli.Context) { run(c, create) },
},
{
Name: "package",
Aliases: []string{"pack"},
Usage: "Given a chart directory, package it into a release.",
Action: func(c *cli.Context) { run(c, pack) },
},
{
Name: "deploy",
Aliases: []string{"install"},
Usage: "Deploy a chart into the cluster.",
Action: func(c *cli.Context) { run(c, deploy) },
Flags: []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "Only display the underlying kubectl commands.",
},
cli.BoolFlag{
Name: "stdin,i",
Usage: "Read a configuration from STDIN.",
},
cli.StringFlag{
Name: "name",
Usage: "Name of deployment, used for deploy and update commands (defaults to template name)",
},
// TODO: I think there is a Generic flag type that we can implement parsing with.
cli.StringFlag{
Name: "properties,p",
Usage: "A comma-separated list of key=value pairs: 'foo=bar,foo2=baz'.",
},
cli.StringFlag{
// FIXME: This is not right. It's sort of a half-baked forward
// port of dm.go.
Name: "repository",
Usage: "The default repository",
Value: "kubernetes/application-dm-templates",
},
},
},
{ {
Name: "search", Name: "search",
}, },
listCmd(),
getCmd(),
} }
} }
func addCommands(cmds ...cli.Command) {
commands = append(commands, cmds...)
}
func run(c *cli.Context, f func(c *cli.Context) error) { func run(c *cli.Context, f func(c *cli.Context) error) {
if err := f(c); err != nil { if err := f(c); err != nil {
os.Stderr.Write([]byte(err.Error())) os.Stderr.Write([]byte(err.Error()))
......
...@@ -5,6 +5,10 @@ import ( ...@@ -5,6 +5,10 @@ import (
"github.com/deis/helm-dm/format" "github.com/deis/helm-dm/format"
) )
func init() {
addCommands(listCmd())
}
func listCmd() cli.Command { func listCmd() cli.Command {
return cli.Command{ return cli.Command{
Name: "list", Name: "list",
......
...@@ -10,6 +10,19 @@ import ( ...@@ -10,6 +10,19 @@ import (
"github.com/kubernetes/deployment-manager/chart" "github.com/kubernetes/deployment-manager/chart"
) )
func init() {
addCommands(packageCmd())
}
func packageCmd() cli.Command {
return cli.Command{
Name: "package",
Aliases: []string{"pack"},
Usage: "Given a chart directory, package it into a release.",
Action: func(c *cli.Context) { run(c, pack) },
}
}
func pack(cxt *cli.Context) error { func pack(cxt *cli.Context) error {
args := cxt.Args() args := cxt.Args()
if len(args) < 1 { if len(args) < 1 {
......
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