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 <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2023-09-18 12:54:24 +02:00
parent d912e735a3
commit 0b7142f4a4
4 changed files with 10 additions and 5 deletions

View File

@ -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)
}

View File

@ -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.

View File

@ -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.

View File

@ -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"}}'