From 0b7142f4a446463e626aff983feca16f816df698 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 18 Sep 2023 12:54:24 +0200 Subject: [PATCH] error when --module is specified on the command level The --module can only be parsed on the root level. It cannot work on the command level, because it must be "manually" parsed on init() to make sure the specified configuration files/modules are loaded prior to parsing the flags via Cobra. Hence move --module from the "persistent" to the "local" flags which will yield an error instead of doing nothing when being specified on the command level: ``` $ ./bin/podman run --module=foo.conf --rm alpine Error: unknown flag: --module See 'podman run --help' ``` Reported in #20000. Signed-off-by: Valentin Rothberg --- cmd/podman/registry/config.go | 6 +++--- cmd/podman/root.go | 2 +- docs/source/markdown/podman.1.md | 3 ++- test/system/800-config.bats | 4 ++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go index 7d80053b33..1f6f6f566c 100644 --- a/cmd/podman/registry/config.go +++ b/cmd/podman/registry/config.go @@ -80,7 +80,7 @@ func containersConfModules() ([]string, error) { func newPodmanConfig() { modules, err := containersConfModules() if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) + fmt.Fprintf(os.Stderr, "Error parsing containers.conf modules: %v\n", err) os.Exit(1) } @@ -94,7 +94,7 @@ func newPodmanConfig() { Modules: modules, }) if err != nil { - fmt.Fprint(os.Stderr, "Failed to obtain podman configuration: "+err.Error()) + fmt.Fprintf(os.Stderr, "Failed to obtain podman configuration: %v\n", err) os.Exit(1) } @@ -111,7 +111,7 @@ func newPodmanConfig() { mode = entities.TunnelMode } default: - fmt.Fprintf(os.Stderr, "%s is not a supported OS", runtime.GOOS) + fmt.Fprintf(os.Stderr, "%s is not a supported OS\n", runtime.GOOS) os.Exit(1) } diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 394dd61f47..1cba35a54d 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -456,7 +456,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" - pFlags.StringSlice(moduleFlagName, nil, "Load the containers.conf(5) module") + lFlags.StringSlice(moduleFlagName, nil, "Load the containers.conf(5) module") _ = cmd.RegisterFlagCompletionFunc(moduleFlagName, common.AutocompleteContainersConfModules) // A *hidden* flag to change the database backend. diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 4a2dbae854..da2c732d4e 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -92,7 +92,8 @@ Log messages at and above specified level: __debug__, __info__, __warn__, __erro Load the specified `containers.conf(5)` module. Can be an absolute or relative path. Please refer to `containers.conf(5)` for details. -This feature is not supported on the remote client, including Mac and Windows (excluding WSL2) machines +This flag is not supported on the remote client, including Mac and Windows (excluding WSL2) machines. +Further note that the flag is a root-level flag and must be specified before any Podman sub-command. #### **--network-cmd-path**=*path* Path to the `slirp4netns(1)` command binary to use for setting up a slirp4netns network. diff --git a/test/system/800-config.bats b/test/system/800-config.bats index eef84e266a..90d0505adc 100644 --- a/test/system/800-config.bats +++ b/test/system/800-config.bats @@ -93,6 +93,10 @@ EOF annotations=['module=$random_data'] EOF + run_podman 125 create --module=$conf_tmp -q $IMAGE + is "$output" "Error: unknown flag: --module +See 'podman create --help'" "--module must be specified before the command" + run_podman --module=$conf_tmp create -q $IMAGE cid="$output" run_podman container inspect $cid --format '{{index .Config.Annotations "module"}}'