From 32a822315fb720fe956a571b37b4494818a259ea Mon Sep 17 00:00:00 2001 From: Lajos Papp Date: Mon, 17 Feb 2025 08:51:08 +0000 Subject: [PATCH 1/2] cli/command/container/opts: parse: use strslice.UnmarshalJSON if syntax is correct entrypoint is already defined as strslice why not use its unmarshal method Signed-off-by: Lalyos Papp --- cli/command/container/opts.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 8cc44b762da9..2dc1bdb59d00 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -413,6 +413,9 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con if copts.entrypoint != "" { entrypoint = strslice.StrSlice{copts.entrypoint} + if entrypoint.UnmarshalJSON([]byte(copts.entrypoint)) != nil { + entrypoint = strslice.StrSlice{copts.entrypoint} + } } else if flags.Changed("entrypoint") { // if `--entrypoint=` is parsed then Entrypoint is reset entrypoint = []string{""} From 305c0489ff1fad1896a7e32dd537ea639173a687 Mon Sep 17 00:00:00 2001 From: Lajos Papp Date: Mon, 17 Feb 2025 13:41:12 +0000 Subject: [PATCH 2/2] cli/command/container/opts_test: add entrypoint slice tests Signed-off-by: Lalyos Papp --- cli/command/container/opts_test.go | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index c54f3107b6d5..e71c9efa4e65 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -1020,6 +1020,47 @@ func TestParseEntryPoint(t *testing.T) { assert.Check(t, is.DeepEqual([]string(config.Entrypoint), []string{"anything"})) } +func TestParseEntryPointSlice(t *testing.T) { + testCases := []struct { + name string + input string + expected []string + }{ + { + name: "nothing", + input: "", + expected: nil, + }, + { + name: "empty list", + input: "--entrypoint=[]", + expected: []string{}, + }, + { + name: "empty string", + input: "--entrypoint=", + expected: []string{""}, + }, + { + name: "single", + input: `--entrypoint=["something"]`, + expected: []string{"something"}, + }, + { + name: "multiple", + input: `--entrypoint=["sh","-c","echo foo bar"]`, + expected: []string{"sh", "-c", "echo foo bar"}, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + config, _, _, err := parseRun([]string{tc.input}) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual([]string(config.Entrypoint), tc.expected)) + }) + } +} + func TestValidateDevice(t *testing.T) { skip.If(t, runtime.GOOS != "linux") // Windows and macOS validate server-side valid := []string{