From 4cd1642be0a1cde1166c0f86bd4e8443ab9754da Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 27 Feb 2025 12:11:10 -0800 Subject: [PATCH] Add quiet flag to podman-compose config This skips printing and is useful for validating config files. Signed-off-by: Ian Fijolek --- newsfragments/1152-config-quiet.feature | 1 + podman_compose.py | 12 ++++++++++-- .../profile/test_podman_compose_config.py | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 newsfragments/1152-config-quiet.feature diff --git a/newsfragments/1152-config-quiet.feature b/newsfragments/1152-config-quiet.feature new file mode 100644 index 0000000..8466b41 --- /dev/null +++ b/newsfragments/1152-config-quiet.feature @@ -0,0 +1 @@ +- Add a `--quiet` flag to the `config` command to suppress output. diff --git a/podman_compose.py b/podman_compose.py index d2ecbcc..446ccd7 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -3136,9 +3136,11 @@ async def compose_logs(compose, args): async def compose_config(compose, args): if args.services: for service in compose.services: - print(service) + if not args.quiet: + print(service) return - print(compose.merged_yaml) + if not args.quiet: + print(compose.merged_yaml) @cmd_run(podman_compose, "port", "Prints the public port for a port binding.") @@ -3672,6 +3674,12 @@ def compose_config_parse(parser): parser.add_argument( "--services", help="Print the service names, one per line.", action="store_true" ) + parser.add_argument( + "-q", + "--quiet", + help="Do not print config, only parse.", + action="store_true", + ) @cmd_parse(podman_compose, "port") diff --git a/tests/integration/profile/test_podman_compose_config.py b/tests/integration/profile/test_podman_compose_config.py index b1d1f56..c0d86d7 100644 --- a/tests/integration/profile/test_podman_compose_config.py +++ b/tests/integration/profile/test_podman_compose_config.py @@ -80,3 +80,20 @@ class TestComposeConfig(unittest.TestCase, RunSubprocessMixin): actual_services[service] = service in actual_output self.assertEqual(expected_services, actual_services) + + def test_config_quiet(self): + """ + Tests podman-compose config command with the --quiet flag. + """ + config_cmd = [ + "coverage", + "run", + podman_compose_path(), + "-f", + profile_compose_file(), + "config", + "--quiet", + ] + + out, _ = self.run_subprocess_assert_returncode(config_cmd) + self.assertEqual(out.decode("utf-8"), "")