Make machine name optional in CLI

For commands inspect, ip, kill and restart.
It is already implemented for the others.

Signed-off-by: Guillaume Giamarchi <guillaume.giamarchi@gmail.com>
This commit is contained in:
Guillaume Giamarchi 2014-12-14 01:41:42 +01:00
parent 477fffb1ba
commit 8613b941e8
1 changed files with 26 additions and 17 deletions

View File

@ -129,13 +129,18 @@ var Commands = []cli.Command{
Usage: "Inspect information about a machine",
Action: func(c *cli.Context) {
name := c.Args().First()
store := NewStore()
if name == "" {
cli.ShowCommandHelp(c, "inspect")
os.Exit(1)
host, err := store.GetActive()
if err != nil {
log.Errorf("error unable to get active host")
os.Exit(1)
}
name = host.Name
}
store := NewStore()
host, err := store.Load(name)
if err != nil {
log.Errorf("error loading data")
@ -157,11 +162,6 @@ var Commands = []cli.Command{
Action: func(c *cli.Context) {
name := c.Args().First()
if name == "" {
cli.ShowCommandHelp(c, "ip")
os.Exit(1)
}
var (
err error
host *Host
@ -199,13 +199,17 @@ var Commands = []cli.Command{
Usage: "Kill a machine",
Action: func(c *cli.Context) {
name := c.Args().First()
store := NewStore()
if name == "" {
cli.ShowCommandHelp(c, "kill")
os.Exit(1)
}
host, err := store.GetActive()
if err != nil {
log.Errorf("error unable to get active host")
os.Exit(1)
}
store := NewStore()
name = host.Name
}
host, err := store.Load(name)
if err != nil {
@ -291,13 +295,18 @@ var Commands = []cli.Command{
Usage: "Restart a machine",
Action: func(c *cli.Context) {
name := c.Args().First()
if name == "" {
cli.ShowCommandHelp(c, "restart")
os.Exit(1)
}
store := NewStore()
if name == "" {
host, err := store.GetActive()
if err != nil {
log.Errorf("error unable to get active host")
os.Exit(1)
}
name = host.Name
}
host, err := store.Load(name)
if err != nil {
log.Errorf("error unable to load data")