diff --git a/cmd/podman/root.go b/cmd/podman/root.go index a5ab58b47d..7d03b0d70e 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -78,6 +78,7 @@ var ( useSyslog bool requireCleanup = true + noOut = false ) func init() { @@ -87,6 +88,7 @@ func init() { syslogHook, earlyInitHook, configHook, + noOutHook, ) rootFlags(rootCmd, registry.PodmanConfig()) @@ -127,10 +129,6 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error { } podmanConfig := registry.PodmanConfig() - if podmanConfig.NoOut { - null, _ := os.Open(os.DevNull) - os.Stdout = null - } // Currently it is only possible to restore a container with the same runtime // as used for checkpointing. It should be possible to make crun and runc @@ -368,6 +366,13 @@ func loggingHook() { } } +func noOutHook() { + if noOut { + null, _ := os.Open(os.DevNull) + os.Stdout = null + } +} + func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { srv, uri, ident, machine := resolveDestination() @@ -400,7 +405,7 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) { lFlags.StringVar(&podmanConfig.Identity, identityFlagName, ident, "path to SSH identity file, (CONTAINER_SSHKEY)") _ = cmd.RegisterFlagCompletionFunc(identityFlagName, completion.AutocompleteDefault) - lFlags.BoolVar(&podmanConfig.NoOut, "noout", false, "do not output to stdout") + lFlags.BoolVar(&noOut, "noout", false, "do not output to stdout") lFlags.BoolVarP(&podmanConfig.Remote, "remote", "r", registry.IsRemote(), "Access remote Podman service") pFlags := cmd.PersistentFlags() if registry.IsRemote() { diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go index c025aa03bc..47330da841 100644 --- a/pkg/domain/entities/engine.go +++ b/pkg/domain/entities/engine.go @@ -42,7 +42,6 @@ type PodmanConfig struct { Identity string // ssh identity for connecting to server MaxWorks int // maximum number of parallel threads MemoryProfile string // Hidden: Should memory profile be taken - NoOut bool // Don't output to stdout RegistriesConf string // allows for specifying a custom registries.conf Remote bool // Connection to Podman API Service will use RESTful API RuntimePath string // --runtime flag will set Engine.RuntimePath diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats index 07b0f0eae0..4dba712a8f 100644 --- a/test/system/001-basic.bats +++ b/test/system/001-basic.bats @@ -232,4 +232,10 @@ See 'podman version --help'" "podman version --remote" is "$output" "Setting --log-level and --debug is not allowed" } +# Tests --noout for commands that do not enter the engine +@test "podman --noout properly supresses output" { +run_podman --noout system connection ls + is "$output" "" "output should be empty" +} + # vim: filetype=sh