Add argument assertion to inspect/status/url commands

Signed-off-by: Kazuyuki Suzuki <kechol28@gmail.com>
This commit is contained in:
Kazuyuki SUZUKI 2015-09-17 19:05:35 +09:00
parent 1588f2217a
commit 2bc53a6ac3
6 changed files with 40 additions and 4 deletions

View File

@ -23,6 +23,11 @@ var funcMap = template.FuncMap{
}
func cmdInspect(c *cli.Context) {
if len(c.Args()) == 0 {
cli.ShowCommandHelp(c, "inspect")
log.Fatal("You must specify a machine name")
}
tmplString := c.String("format")
if tmplString != "" {
var tmpl *template.Template

View File

@ -1,12 +1,14 @@
package commands
import (
"github.com/docker/machine/libmachine/log"
"github.com/codegangsta/cli"
"github.com/docker/machine/libmachine/log"
)
func cmdStatus(c *cli.Context) {
if len(c.Args()) != 1 {
log.Fatal(ErrExpectedOneMachine)
}
host := getFirstArgHost(c)
currentState, err := host.Driver.GetState()
if err != nil {

View File

@ -3,12 +3,14 @@ package commands
import (
"fmt"
"github.com/docker/machine/libmachine/log"
"github.com/codegangsta/cli"
"github.com/docker/machine/libmachine/log"
)
func cmdUrl(c *cli.Context) {
if len(c.Args()) != 1 {
log.Fatal(ErrExpectedOneMachine)
}
url, err := getFirstArgHost(c).GetURL()
if err != nil {
log.Fatal(err)

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bats
load ${BASE_TEST_DIR}/helpers.bash
@test "inspect: show error in case of no args" {
run machine inspect
[ "$status" -eq 1 ]
[[ ${output} == *"must specify a machine name"* ]]
}

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bats
load ${BASE_TEST_DIR}/helpers.bash
@test "status: show error in case of no args" {
run machine inspect
[ "$status" -eq 1 ]
[[ ${output} == *"must specify a machine name"* ]]
}

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bats
load ${BASE_TEST_DIR}/helpers.bash
@test "url: show error in case of no args" {
run machine inspect
[ "$status" -eq 1 ]
[[ ${output} == *"must specify a machine name"* ]]
}