Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix podman --noout to suppress all output #16518

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation, but not worth re-pushing for. (If you need to re-push for any reason, though, please fix it)

is "$output" "" "output should be empty"
}

# vim: filetype=sh