فهرست منبع

Map Commands instead of using them as a slice

The most obvious use case is when one wants to make sure as fast
as possible that a command is a valid Dockerfile command.

Signed-off-by: kargakis <kargakis@users.noreply.github.com>
kargakis 10 سال پیش
والد
کامیت
6ecf23861e
2فایلهای تغییر یافته به همراه16 افزوده شده و 16 حذف شده
  1. 15 15
      builder/command/command.go
  2. 1 1
      integration-cli/docker_cli_build_test.go

+ 15 - 15
builder/command/command.go

@@ -19,19 +19,19 @@ const (
 )
 
 // Commands is list of all Dockerfile commands
-var Commands = []string{
-	Env,
-	Maintainer,
-	Add,
-	Copy,
-	From,
-	Onbuild,
-	Workdir,
-	Run,
-	Cmd,
-	Entrypoint,
-	Expose,
-	Volume,
-	User,
-	Insert,
+var Commands = map[string]struct{}{
+	Env:        {},
+	Maintainer: {},
+	Add:        {},
+	Copy:       {},
+	From:       {},
+	Onbuild:    {},
+	Workdir:    {},
+	Run:        {},
+	Cmd:        {},
+	Entrypoint: {},
+	Expose:     {},
+	Volume:     {},
+	User:       {},
+	Insert:     {},
 }

+ 1 - 1
integration-cli/docker_cli_build_test.go

@@ -4836,7 +4836,7 @@ func TestBuildMissingArgs(t *testing.T) {
 
 	defer deleteAllContainers()
 
-	for _, cmd := range command.Commands {
+	for cmd := range command.Commands {
 		cmd = strings.ToUpper(cmd)
 		if _, ok := skipCmds[cmd]; ok {
 			continue