From 6f69add5b34cb60ee1f99fdf8f295e89c2140d88 Mon Sep 17 00:00:00 2001 From: Alex Youngs Date: Wed, 30 Oct 2024 16:50:10 -0500 Subject: [PATCH 1/4] Added config option to pass arguments as a yaml file instead --- src/rocker/cli.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rocker/cli.py b/src/rocker/cli.py index 2840c8bb..8bf21031 100644 --- a/src/rocker/cli.py +++ b/src/rocker/cli.py @@ -15,6 +15,7 @@ import argparse import os import sys +import yaml from .core import DockerImageGenerator from .core import get_rocker_version @@ -32,6 +33,7 @@ def main(): formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('image') parser.add_argument('command', nargs='*', default='') + parser.add_argument('--config', help='Optional yaml file to handle command line arguments as a config file. This config will override any other command line arguments of the same name as the yaml keys') parser.add_argument('--noexecute', action='store_true', help='Deprecated') parser.add_argument('--nocache', action='store_true') parser.add_argument('--nocleanup', action='store_true', help='do not remove the docker container when stopped') @@ -50,6 +52,12 @@ def main(): args = parser.parse_args() args_dict = vars(args) + # Load config file if provided + if args.config: + with open(args.config, 'r') as f: + config = yaml.safe_load(f) + args_dict.update(config) + if args.noexecute: from .core import OPERATIONS_DRY_RUN args_dict['mode'] = OPERATIONS_DRY_RUN From 0f45fb2bb13712cff45b5ecea0f5009ff22d5a74 Mon Sep 17 00:00:00 2001 From: Alex Youngs Date: Wed, 30 Oct 2024 16:59:42 -0500 Subject: [PATCH 2/4] Updated help text --- src/rocker/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rocker/cli.py b/src/rocker/cli.py index 8bf21031..e55006f9 100644 --- a/src/rocker/cli.py +++ b/src/rocker/cli.py @@ -33,7 +33,7 @@ def main(): formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('image') parser.add_argument('command', nargs='*', default='') - parser.add_argument('--config', help='Optional yaml file to handle command line arguments as a config file. This config will override any other command line arguments of the same name as the yaml keys') + parser.add_argument('--config', help='Optional yaml file to handle command line arguments (except positional args) as a config file. This config will override any other command line arguments of the same name as the yaml keys (e.g. "--user-override-name" would have the key "user_override_name" in the config file)') parser.add_argument('--noexecute', action='store_true', help='Deprecated') parser.add_argument('--nocache', action='store_true') parser.add_argument('--nocleanup', action='store_true', help='do not remove the docker container when stopped') From 397672a892aa598e57fadbec2c1611a52880e61a Mon Sep 17 00:00:00 2001 From: Alex Youngs Date: Wed, 30 Oct 2024 17:03:17 -0500 Subject: [PATCH 3/4] Formatting --- src/rocker/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rocker/cli.py b/src/rocker/cli.py index e55006f9..2dc0e255 100644 --- a/src/rocker/cli.py +++ b/src/rocker/cli.py @@ -33,7 +33,10 @@ def main(): formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('image') parser.add_argument('command', nargs='*', default='') - parser.add_argument('--config', help='Optional yaml file to handle command line arguments (except positional args) as a config file. This config will override any other command line arguments of the same name as the yaml keys (e.g. "--user-override-name" would have the key "user_override_name" in the config file)') + parser.add_argument('--config', help='''Optional yaml file to handle command line arguments + (except positional args) as a config file. This config will override any other command line + arguments of the same name as the yaml keys (e.g. "--user-override-name" would have the key + "user_override_name" in the config file)''') parser.add_argument('--noexecute', action='store_true', help='Deprecated') parser.add_argument('--nocache', action='store_true') parser.add_argument('--nocleanup', action='store_true', help='do not remove the docker container when stopped') From 4182cf47e0bb24ce10845f3555d457b2846e83a7 Mon Sep 17 00:00:00 2001 From: Alex Youngs Date: Wed, 30 Oct 2024 17:22:24 -0500 Subject: [PATCH 4/4] Added missing dep --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 2cc1d9d8..3624e381 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ 'pexpect', 'packaging', 'urllib3', + 'pyyaml', ] # docker API used to be in a package called `docker-py` before the 2.0 release