Skip to content

Commit

Permalink
Merge pull request #16518 from ashley-cui/noout
Browse files Browse the repository at this point in the history
Fix podman --noout to suppress all output
  • Loading branch information
openshift-merge-robot authored Nov 15, 2022
2 parents d1ac0dc + 7c1ad8a commit 54b1fd3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var (

useSyslog bool
requireCleanup = true
noOut = false
)

func init() {
Expand All @@ -87,6 +88,7 @@ func init() {
syslogHook,
earlyInitHook,
configHook,
noOutHook,
)

rootFlags(rootCmd, registry.PodmanConfig())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion pkg/domain/entities/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/system/001-basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 54b1fd3

Please sign in to comment.