Skip to content

Commit fe5a722

Browse files
Merge pull request docker-archive-public#1870 from kechol/add-argument-assertion
Add argument assertions to inspect/status/url commands
2 parents 1588f22 + 2bc53a6 commit fe5a722

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

commands/inspect.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ var funcMap = template.FuncMap{
2323
}
2424

2525
func cmdInspect(c *cli.Context) {
26+
if len(c.Args()) == 0 {
27+
cli.ShowCommandHelp(c, "inspect")
28+
log.Fatal("You must specify a machine name")
29+
}
30+
2631
tmplString := c.String("format")
2732
if tmplString != "" {
2833
var tmpl *template.Template

commands/status.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package commands
22

33
import (
4-
"github.com/docker/machine/libmachine/log"
5-
64
"github.com/codegangsta/cli"
5+
"github.com/docker/machine/libmachine/log"
76
)
87

98
func cmdStatus(c *cli.Context) {
9+
if len(c.Args()) != 1 {
10+
log.Fatal(ErrExpectedOneMachine)
11+
}
1012
host := getFirstArgHost(c)
1113
currentState, err := host.Driver.GetState()
1214
if err != nil {

commands/url.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package commands
33
import (
44
"fmt"
55

6-
"github.com/docker/machine/libmachine/log"
7-
86
"github.com/codegangsta/cli"
7+
"github.com/docker/machine/libmachine/log"
98
)
109

1110
func cmdUrl(c *cli.Context) {
11+
if len(c.Args()) != 1 {
12+
log.Fatal(ErrExpectedOneMachine)
13+
}
1214
url, err := getFirstArgHost(c).GetURL()
1315
if err != nil {
1416
log.Fatal(err)

test/integration/cli/inspect.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
3+
load ${BASE_TEST_DIR}/helpers.bash
4+
5+
@test "inspect: show error in case of no args" {
6+
run machine inspect
7+
[ "$status" -eq 1 ]
8+
[[ ${output} == *"must specify a machine name"* ]]
9+
}

test/integration/cli/status.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
3+
load ${BASE_TEST_DIR}/helpers.bash
4+
5+
@test "status: show error in case of no args" {
6+
run machine inspect
7+
[ "$status" -eq 1 ]
8+
[[ ${output} == *"must specify a machine name"* ]]
9+
}

test/integration/cli/url.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
3+
load ${BASE_TEST_DIR}/helpers.bash
4+
5+
@test "url: show error in case of no args" {
6+
run machine inspect
7+
[ "$status" -eq 1 ]
8+
[[ ${output} == *"must specify a machine name"* ]]
9+
}

0 commit comments

Comments
 (0)