From c97560841f1bf31a9a10dd2f91d91d7a227febe7 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 15:58:39 +0100 Subject: [PATCH 01/16] cli: add docs for StringArray vs StringSlice options In short always use StringArray over StringSlice. Signed-off-by: Paul Holzinger --- cmd/podman/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/podman/README.md b/cmd/podman/README.md index 9214bdafcb..29b5f86430 100644 --- a/cmd/podman/README.md +++ b/cmd/podman/README.md @@ -109,3 +109,11 @@ The complete set can be found in the `validate` package, here are some examples: created := validate.ChoiceValue(&opts.Sort, "command", "created", "id", "image", "names", "runningfor", "size", "status") flags.Var(created, "sort", "Sort output by: "+created.Choices()) ``` + +## Adding CLI flags + +When adding adding a new cli option that accepts a string array, there are two options to choose from: `StringSlice()` and `StringArray()`. +They differ slightly in their behavior: `StringSlice()` allows the values to be comma separated so `--opt v1,v2 --opt v3` results in +`[]string{"v1", "v2", "v3"}`, while `StringArray()` would result in `[]string{"v1,v2", "v3"}`. Thus it is impossible to use values with comma in `StringSlice()`, which makes it unsuitable for flags that accept arbitrary values such as file paths as example. Also, because `StringSlice()` uses the csv lib to parse the values, it has special escaping rules for things like quotes, see https://github.com/containers/podman/issues/20064 for an example of how complicated things can get because of this. +Thus use `StringSlice()` only when the option accepts predefined values that do not contain special characters, for example `--cap-add` and `--cap-drop` are a good example for this. Using `--cap-add NET_ADMIN,NET_RAW` is equal to `--cap-add NET_ADMIN --cap-add NET_RAW` so it is better suited to save some typing for users. +When in doubt always choose `StringArray()` over `StringSlice()`. From 12c39ffda26107507de173f7346b7e82ae1a2327 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:28:05 +0100 Subject: [PATCH 02/16] cli: podman --module use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/registry/config.go | 2 +- cmd/podman/root.go | 2 +- test/system/800-config.bats | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go index fd8f322c45..db5c292973 100644 --- a/cmd/podman/registry/config.go +++ b/cmd/podman/registry/config.go @@ -72,7 +72,7 @@ func containersConfModules() ([]string, error) { fs.ParseErrorsWhitelist.UnknownFlags = true fs.Usage = func() {} fs.SetInterspersed(false) - fs.StringSliceVar(&modules, "module", nil, "") + fs.StringArrayVar(&modules, "module", nil, "") fs.BoolP("help", "h", false, "") // Need a fake help flag to avoid the `pflag: help requested` error return modules, fs.Parse(os.Args[index:]) } diff --git a/cmd/podman/root.go b/cmd/podman/root.go index bec9bd071e..e8a746a5f4 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -507,7 +507,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { // as a flag here to a) make sure that rootflags are aware of // this flag and b) to have shell completions. moduleFlagName := "module" - lFlags.StringSlice(moduleFlagName, nil, "Load the containers.conf(5) module") + lFlags.StringArray(moduleFlagName, nil, "Load the containers.conf(5) module") _ = cmd.RegisterFlagCompletionFunc(moduleFlagName, common.AutocompleteContainersConfModules) // A *hidden* flag to change the database backend. diff --git a/test/system/800-config.bats b/test/system/800-config.bats index 588a68f765..13b56a0e92 100644 --- a/test/system/800-config.bats +++ b/test/system/800-config.bats @@ -104,8 +104,8 @@ See 'podman create --help'" "--module must be specified before the command" run_podman rm -f $cid - # Nonexistent module path - nonesuch=${PODMAN_TMPDIR}/nonexistent + # Nonexistent module path with comma + nonesuch=${PODMAN_TMPDIR}/nonexistent,withcomma run_podman 1 --module=$nonesuch sdfsdfdsf is "$output" "Failed to obtain podman configuration: could not resolve module \"$nonesuch\": stat $nonesuch: no such file or directory" \ "--module=ENOENT" From c5258d46305efc765f380d48583f278d61fff581 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:33:42 +0100 Subject: [PATCH 03/16] cli: podman --hooks-dir use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/root.go | 2 +- test/e2e/run_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/podman/root.go b/cmd/podman/root.go index e8a746a5f4..86f42d1c4b 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -541,7 +541,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { _ = cmd.RegisterFlagCompletionFunc(eventsBackendFlagName, common.AutocompleteEventBackend) hooksDirFlagName := "hooks-dir" - pFlags.StringSliceVar(&podmanConfig.HooksDir, hooksDirFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.HooksDir.Get(), "Set the OCI hooks directory path (may be set multiple times)") + pFlags.StringArrayVar(&podmanConfig.HooksDir, hooksDirFlagName, podmanConfig.ContainersConfDefaultsRO.Engine.HooksDir.Get(), "Set the OCI hooks directory path (may be set multiple times)") _ = cmd.RegisterFlagCompletionFunc(hooksDirFlagName, completion.AutocompleteDefault) pFlags.IntVar(&podmanConfig.MaxWorks, "max-workers", (runtime.NumCPU()*3)+1, "The maximum number of workers for parallel operations") diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 6789961634..f07ece51cf 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -916,7 +916,7 @@ USER bin`, BB) It("podman test hooks", func() { SkipIfRemote("--hooks-dir does not work with remote") - hooksDir := tempdir + "/hooks" + hooksDir := tempdir + "/hooks,withcomma" err := os.Mkdir(hooksDir, 0755) Expect(err).ToNot(HaveOccurred()) hookJSONPath := filepath.Join(hooksDir, "checkhooks.json") From ef10073b51970cbdd5559526bd323b30c3924dae Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:35:25 +0100 Subject: [PATCH 04/16] cli: podman run/create --annotation use StringArray() This option accepts arbitrary input so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- test/e2e/create_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 105ea13c56..3c3a580497 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -33,7 +33,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, if mode == entities.CreateMode { // regular create flags annotationFlagName := "annotation" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.Annotation, annotationFlagName, []string{}, "Add annotations to container (key=value)", diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index f9aa0f8bbd..8d777647e6 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -101,7 +101,7 @@ var _ = Describe("Podman create", func() { }) It("podman create adds annotation", func() { - session := podmanTest.Podman([]string{"create", "--annotation", "HELLO=WORLD", "--name", "annotate_test", ALPINE, "ls"}) + session := podmanTest.Podman([]string{"create", "--annotation", "HELLO=WORLD,WithComma", "--name", "annotate_test", ALPINE, "ls"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) Expect(podmanTest.NumberOfContainers()).To(Equal(1)) @@ -109,7 +109,7 @@ var _ = Describe("Podman create", func() { check := podmanTest.Podman([]string{"inspect", "annotate_test"}) check.WaitWithDefaultTimeout() data := check.InspectContainerToJSON() - Expect(data[0].Config.Annotations).To(HaveKeyWithValue("HELLO", "WORLD")) + Expect(data[0].Config.Annotations).To(HaveKeyWithValue("HELLO", "WORLD,WithComma")) }) It("podman create --entrypoint command", func() { From b011aa443018dd5db5061c6a903c2eac4a2dccd0 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:39:22 +0100 Subject: [PATCH 05/16] cli: podman run/create --env-file use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- test/system/300-cli-parsing.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 3c3a580497..435afbc77b 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -147,7 +147,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, } envFileFlagName := "env-file" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.EnvFile, envFileFlagName, []string{}, "Read in a file of environment variables", diff --git a/test/system/300-cli-parsing.bats b/test/system/300-cli-parsing.bats index 12ab4dcb6a..63a16aaa9a 100644 --- a/test/system/300-cli-parsing.bats +++ b/test/system/300-cli-parsing.bats @@ -196,7 +196,7 @@ EOF fi # Same, with --env-file - local envfile="$PODMAN_TMPDIR/envfile-in-1" + local envfile="$PODMAN_TMPDIR/envfile-in-1,withcomma" cat >$envfile < Date: Thu, 7 Dec 2023 16:40:41 +0100 Subject: [PATCH 06/16] cli: podman run/create --log-opt use StringArray() This option accepts arbitrary input so we should allow commas in it. Fixes #20064 Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- test/e2e/logs_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 435afbc77b..45c136985e 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -282,7 +282,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(logDriverFlagName, AutocompleteLogDriver) logOptFlagName := "log-opt" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.LogOptions, logOptFlagName, []string{}, "Logging driver options", diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 66ca09ebe3..1f256e9f84 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -536,7 +536,7 @@ var _ = Describe("Podman logs", func() { It("using journald for container with container tag", func() { SkipIfJournaldUnavailable() - logc := podmanTest.Podman([]string{"run", "--log-driver", "journald", "--log-opt=tag={{.ImageName}}", "-d", ALPINE, "sh", "-c", "echo podman; sleep 0.1; echo podman; sleep 0.1; echo podman"}) + logc := podmanTest.Podman([]string{"run", "--log-driver", "journald", "--log-opt=tag={{.ImageName}},withcomma", "-d", ALPINE, "sh", "-c", "echo podman; sleep 0.1; echo podman; sleep 0.1; echo podman"}) logc.WaitWithDefaultTimeout() Expect(logc).To(ExitCleanly()) cid := logc.OutputToString() @@ -549,7 +549,7 @@ var _ = Describe("Podman logs", func() { cmd := exec.Command("journalctl", "--no-pager", "-o", "json", "--output-fields=CONTAINER_TAG", fmt.Sprintf("CONTAINER_ID_FULL=%s", cid)) out, err := cmd.CombinedOutput() g.Expect(err).ToNot(HaveOccurred()) - g.Expect(string(out)).To(ContainSubstring("alpine")) + g.Expect(string(out)).To(ContainSubstring(ALPINE + ",withcomma")) }).Should(Succeed()) }) From 201920f6a4b967e7a4bef366aae4f4b7592de7c7 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:45:13 +0100 Subject: [PATCH 07/16] cli: podman run/create --chrootdirs use StringArray() This options accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- test/e2e/create_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 45c136985e..223fb2e12e 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -595,7 +595,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(pidFileFlagName, completion.AutocompleteDefault) chrootDirsFlagName := "chrootdirs" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.ChrootDirs, chrootDirsFlagName, []string{}, "Chroot directories inside the container", diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index 8d777647e6..df753ce461 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -717,7 +717,7 @@ var _ = Describe("Podman create", func() { }) It("podman create --chrootdirs functionality test", func() { - session := podmanTest.Podman([]string{"create", "-t", "--chrootdirs", "/var/local/qwerty", ALPINE, "/bin/cat"}) + session := podmanTest.Podman([]string{"create", "-t", "--chrootdirs", "/var/local/qwerty,withcomma", ALPINE, "/bin/cat"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) ctrID := session.OutputToString() @@ -726,7 +726,7 @@ var _ = Describe("Podman create", func() { setup.WaitWithDefaultTimeout() Expect(setup).Should(ExitCleanly()) - setup = podmanTest.Podman([]string{"exec", ctrID, "cmp", "/etc/resolv.conf", "/var/local/qwerty/etc/resolv.conf"}) + setup = podmanTest.Podman([]string{"exec", ctrID, "cmp", "/etc/resolv.conf", "/var/local/qwerty,withcomma/etc/resolv.conf"}) setup.WaitWithDefaultTimeout() Expect(setup).Should(ExitCleanly()) }) From 24d08a94d86dac4deb9e7ba5b67464bcf3aef925 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:46:42 +0100 Subject: [PATCH 08/16] cli: podman run/create --decryption-key use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 223fb2e12e..2e55e8e7cd 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -611,7 +611,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(groupEntryName, completion.AutocompleteNone) decryptionKeysFlagName := "decryption-key" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.DecryptionKeys, decryptionKeysFlagName, []string{}, "Key needed to decrypt the image (e.g. /path/to/key.pem)", From 19571f7509ed6ec37a96ec3c4bc401b2d8de56c3 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:48:53 +0100 Subject: [PATCH 09/16] cli: podman run/create --label-file use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 2e55e8e7cd..65c78317c0 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -772,7 +772,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(labelFlagName, completion.AutocompleteNone) labelFileFlagName := "label-file" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.LabelFile, labelFileFlagName, []string{}, "Read in a line delimited file of labels", From 833163ff3e2738d630d70f69efcd43645334b12f Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 17:56:26 +0100 Subject: [PATCH 10/16] add podman create --label-file test There was no test for this option so I added one. Signed-off-by: Paul Holzinger --- test/system/300-cli-parsing.bats | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/system/300-cli-parsing.bats b/test/system/300-cli-parsing.bats index 63a16aaa9a..83b9ebad95 100644 --- a/test/system/300-cli-parsing.bats +++ b/test/system/300-cli-parsing.bats @@ -213,4 +213,40 @@ EOF } +@test "podman create --label-file" { + declare -A expect=( + [simple]="abc" + [special]="bcd#e!f|g hij=lmnop" + [withquotes]='"withquotes"' + [withsinglequotes]="'withsingle'" + ) + + # Write two files, so we confirm that podman can accept multiple values + # and that the second will override the first + local labelfile1="$PODMAN_TMPDIR/label-file1,withcomma" + local labelfile2="$PODMAN_TMPDIR/label-file2" + + cat >$labelfile1 <>$labelfile2 + done + + run_podman create --rm --name testctr --label-file $labelfile1 \ + --label-file $labelfile2 $IMAGE + + for v in "${!expect[@]}"; do + run_podman inspect testctr --format "{{index .Config.Labels \"$v\"}}" + assert "$output" == "${expect[$v]}" "label $v" + done + + run_podman rm testctr +} + + + # vim: filetype=sh From e763cc62b78a800e6b1448de6fa6b2b3a253c3b8 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:51:45 +0100 Subject: [PATCH 11/16] cli: podman run/create --device use StringArray() This options accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 65c78317c0..1e2bc4eeb6 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -814,7 +814,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(volumeFlagName, AutocompleteVolumeFlag) deviceFlagName := "device" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.Devices, deviceFlagName, devices(), "Add a host device to the container", From 8de13271cae029e03bac0e68c5b00c8e39076e65 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:53:13 +0100 Subject: [PATCH 12/16] cli: podman run/create --device-{read,write}-iops use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 1e2bc4eeb6..e37a06783b 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -898,7 +898,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, } if mode == entities.CreateMode || mode == entities.UpdateMode { deviceReadIopsFlagName := "device-read-iops" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.DeviceReadIOPs, deviceReadIopsFlagName, []string{}, "Limit read rate (IO per second) from a device (e.g. --device-read-iops=/dev/sda:1000)", @@ -906,7 +906,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(deviceReadIopsFlagName, completion.AutocompleteDefault) deviceWriteIopsFlagName := "device-write-iops" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.DeviceWriteIOPs, deviceWriteIopsFlagName, []string{}, "Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000)", From 432be133010c89024952780f2544f36c6f4dd8a4 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:54:47 +0100 Subject: [PATCH 13/16] cli: podman run/create --device-{read,write}-bps use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index e37a06783b..27bb7fbf24 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -970,7 +970,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(memorySwapFlagName, completion.AutocompleteNone) deviceReadBpsFlagName := "device-read-bps" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.DeviceReadBPs, deviceReadBpsFlagName, []string{}, "Limit read rate (bytes per second) from a device (e.g. --device-read-bps=/dev/sda:1mb)", @@ -978,7 +978,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(deviceReadBpsFlagName, completion.AutocompleteDefault) deviceWriteBpsFlagName := "device-write-bps" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.DeviceWriteBPs, deviceWriteBpsFlagName, []string{}, "Limit write rate (bytes per second) to a device (e.g. --device-write-bps=/dev/sda:1mb)", From 7866f6c6e170fff6d36a971419245c059e2f725b Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 16:56:24 +0100 Subject: [PATCH 14/16] cli: podman run/create --blkio-weight-device use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/common/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 27bb7fbf24..65a47771f5 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -994,7 +994,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, _ = cmd.RegisterFlagCompletionFunc(blkioWeightFlagName, completion.AutocompleteNone) blkioWeightDeviceFlagName := "blkio-weight-device" - createFlags.StringSliceVar( + createFlags.StringArrayVar( &cf.BlkIOWeightDevice, blkioWeightDeviceFlagName, []string{}, "Block IO weight (relative device weight, format: `DEVICE_NAME:WEIGHT`)", From 06cee546a323ff643b135152a6e9fd897f39cd5a Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 18:18:17 +0100 Subject: [PATCH 15/16] cli: podman exec --env-file use StringArray() This option accepts a file path so we should allow commas in it. Signed-off-by: Paul Holzinger --- cmd/podman/containers/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/podman/containers/exec.go b/cmd/podman/containers/exec.go index e8eb557bd0..3e9cd63029 100644 --- a/cmd/podman/containers/exec.go +++ b/cmd/podman/containers/exec.go @@ -68,7 +68,7 @@ func execFlags(cmd *cobra.Command) { _ = cmd.RegisterFlagCompletionFunc(envFlagName, completion.AutocompleteNone) envFileFlagName := "env-file" - flags.StringSliceVar(&envFile, envFileFlagName, []string{}, "Read in a file of environment variables") + flags.StringArrayVar(&envFile, envFileFlagName, []string{}, "Read in a file of environment variables") _ = cmd.RegisterFlagCompletionFunc(envFileFlagName, completion.AutocompleteDefault) flags.BoolVarP(&execOpts.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached") From 4590b663a73fcc2d58ddde4f54b8b06e0998566a Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 7 Dec 2023 18:19:02 +0100 Subject: [PATCH 16/16] add test for podman exec --env-file There was no test for this option, resuse existing podman run --env-file test for exec as well. Signed-off-by: Paul Holzinger --- test/system/300-cli-parsing.bats | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/system/300-cli-parsing.bats b/test/system/300-cli-parsing.bats index 83b9ebad95..16110e60ef 100644 --- a/test/system/300-cli-parsing.bats +++ b/test/system/300-cli-parsing.bats @@ -100,7 +100,7 @@ function _check_env { } -@test "podman run --env-file" { +@test "podman run/exec --env-file" { declare -A expect=( [simple]="abc" [special]="bcd#e!f|g hij=lmnop" @@ -116,7 +116,7 @@ function _check_env { # Write two files, so we confirm that podman can accept multiple values # and that the second will override the first - local envfile1="$PODMAN_TMPDIR/envfile-in-1" + local envfile1="$PODMAN_TMPDIR/envfile-in-1,withcomma" local envfile2="$PODMAN_TMPDIR/envfile-in-2" cat >$envfile1 </envresults' + + _check_env $resultsfile + + run_podman rm -f -t0 testctr } # Obscure feature: '--env FOO*' will pass all env starting with FOO