Merge pull request #1870 from kechol/add-argument-assertion

Add argument assertions to inspect/status/url commands
This commit is contained in:
Nathan LeClaire 2015-10-01 12:21:33 -07:00
commit fe5a72299d
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"* ]]
}