From 4c975a04f93dbd77024c880a63ef83aa5c488b63 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sat, 10 Jul 2021 11:22:34 +0200 Subject: [PATCH] plugins: Invoke setup_parser_common_args explicitly from setup_parser This allows to define plugins which do not need have any of common args. Move setup_parser_common_args into libkas for this as it now becomes a library function. Signed-off-by: Jan Kiszka --- kas/kas.py | 15 --------------- kas/libkas.py | 14 ++++++++++++++ kas/plugins/build.py | 2 ++ kas/plugins/checkout.py | 3 ++- kas/plugins/for_all_repos.py | 2 ++ kas/plugins/shell.py | 2 ++ 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/kas/kas.py b/kas/kas.py index 7316efa..2fe9553 100644 --- a/kas/kas.py +++ b/kas/kas.py @@ -97,20 +97,6 @@ def _atexit_handler(): loop.close() -def setup_parser_common_args(parser): - parser.add_argument('config', - help='Config file') - parser.add_argument('--skip', - help='Skip build steps', - default=[]) - parser.add_argument('--force-checkout', action='store_true', - help='Always checkout the desired refspec of each ' - 'repository, discarding any local changes') - parser.add_argument('--update', action='store_true', - help='Pull new upstream changes to the desired ' - 'refspec even if it is already checked out locally') - - def kas_get_argparser(): """ Creates an argparser for kas with all plugins. @@ -137,7 +123,6 @@ def kas_get_argparser(): for plugin in plugins.all(): plugin_parser = subparser.add_parser(plugin.name, help=plugin.helpmsg) - setup_parser_common_args(plugin_parser) plugin.setup_parser(plugin_parser) return parser diff --git a/kas/libkas.py b/kas/libkas.py index af72d05..6306ccd 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -359,3 +359,17 @@ def ssh_no_host_key_check(): os.mkdir(home + '/.ssh') with open(home + '/.ssh/config', 'w') as fds: fds.write('Host *\n\tStrictHostKeyChecking no\n\n') + + +def setup_parser_common_args(parser): + parser.add_argument('config', + help='Config file') + parser.add_argument('--skip', + help='Skip build steps', + default=[]) + parser.add_argument('--force-checkout', action='store_true', + help='Always checkout the desired refspec of each ' + 'repository, discarding any local changes') + parser.add_argument('--update', action='store_true', + help='Pull new upstream changes to the desired ' + 'refspec even if it is already checked out locally') diff --git a/kas/plugins/build.py b/kas/plugins/build.py index 5e9c4f4..e05001c 100644 --- a/kas/plugins/build.py +++ b/kas/plugins/build.py @@ -39,6 +39,7 @@ from kas.context import create_global_context from kas.config import Config from kas.libkas import find_program, run_cmd from kas.libcmds import Macro, Command +from kas.libkas import setup_parser_common_args __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018' @@ -61,6 +62,7 @@ class Build: Setup the argument parser for the build plugin """ + setup_parser_common_args(parser) parser.add_argument('extra_bitbake_args', nargs='*', help='Extra arguments to pass to bitbake ' diff --git a/kas/plugins/checkout.py b/kas/plugins/checkout.py index 98eb636..7ce4685 100644 --- a/kas/plugins/checkout.py +++ b/kas/plugins/checkout.py @@ -36,6 +36,7 @@ from kas.context import create_global_context from kas.config import Config from kas.libcmds import Macro +from kas.libkas import setup_parser_common_args __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018' @@ -50,7 +51,7 @@ class Checkout: @classmethod def setup_parser(cls, parser): - pass + setup_parser_common_args(parser) def run(self, args): ctx = create_global_context(args) diff --git a/kas/plugins/for_all_repos.py b/kas/plugins/for_all_repos.py index 7ec977c..c04f065 100644 --- a/kas/plugins/for_all_repos.py +++ b/kas/plugins/for_all_repos.py @@ -59,6 +59,7 @@ import sys from kas.context import create_global_context from kas.config import Config from kas.libcmds import Macro, Command +from kas.libkas import setup_parser_common_args __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018' @@ -72,6 +73,7 @@ class ForAllRepos: @classmethod def setup_parser(cls, parser): + setup_parser_common_args(parser) parser.add_argument('command', help='Command to be executed as a string.') diff --git a/kas/plugins/shell.py b/kas/plugins/shell.py index 50e8ed0..62b6760 100644 --- a/kas/plugins/shell.py +++ b/kas/plugins/shell.py @@ -43,6 +43,7 @@ import sys from kas.context import create_global_context from kas.config import Config from kas.libcmds import Macro, Command +from kas.libkas import setup_parser_common_args __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2018' @@ -62,6 +63,7 @@ class Shell: Setup the argument parser for the shell plugin """ + setup_parser_common_args(parser) parser.add_argument('-k', '--keep-config-unchanged', help='Skip steps that change the configuration', action='store_true')