From 8613b941e855b7e73f7957006948853fdde8f423 Mon Sep 17 00:00:00 2001 From: Guillaume Giamarchi Date: Sun, 14 Dec 2014 01:41:42 +0100 Subject: [PATCH] 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 --- commands.go | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/commands.go b/commands.go index 6e079db9b4..08e2f39bc8 100644 --- a/commands.go +++ b/commands.go @@ -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")