From cd80b70d26806beff1a725e1b4bb0122d9771b30 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 9 Oct 2015 15:40:15 +0200 Subject: [PATCH] FIX #1914 Reject command lines with trailing flags Signed-off-by: David Gageot --- commands/create.go | 9 ++++----- test/integration/cli/create-rm.bats | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/commands/create.go b/commands/create.go index 43b5daee9f..7f7ee8483d 100644 --- a/commands/create.go +++ b/commands/create.go @@ -1,7 +1,6 @@ package commands import ( - "errors" "fmt" "os" "path/filepath" @@ -21,10 +20,6 @@ import ( "github.com/docker/machine/libmachine/swarm" ) -var ( - ErrDriverNotRecognized = errors.New("Driver not recognized.") -) - func cmdCreate(c *cli.Context) { var ( driver drivers.Driver @@ -56,6 +51,10 @@ func cmdCreate(c *cli.Context) { log.Fatal("You must specify a machine name") } + if len(c.Args()) > 1 { + log.Fatalf("Invalid command line. Found extra arguments %v", c.Args()[1:]) + } + validName := host.ValidateHostName(name) if !validName { log.Fatal("Error creating machine: ", mcnerror.ErrInvalidHostname) diff --git a/test/integration/cli/create-rm.bats b/test/integration/cli/create-rm.bats index bb8f941a44..ba365d84cd 100644 --- a/test/integration/cli/create-rm.bats +++ b/test/integration/cli/create-rm.bats @@ -52,10 +52,10 @@ load ${BASE_TEST_DIR}/helpers.bash [[ ${lines[0]} == "Error creating machine: Machine A already exists" ]] } -@test "none: extraneous argument is ignored in name 'machine create -d none --url none a foo'" { - run machine create -d none a foo +@test "none: fail with extra argument 'machine create -d none --url none a extra'" { + run machine create -d none --url none a extra [ "$status" -eq 1 ] - [[ ${lines[0]} == "Host already exists: \"a\"" ]] + [[ ${lines[0]} == "Invalid command line. Found extra arguments [extra]" ]] } @test "none: create with weird but valid name succeeds 'machine create -d none --url none 0'" {