From 5021997df0997f0bd1151c6e5e523c38c4eafdac Mon Sep 17 00:00:00 2001 From: qwint Date: Sun, 8 Sep 2024 11:13:01 -0500 Subject: [PATCH] Launcher: explicitly handle cli arguments to be passed to the Component (#3714) * adds handling for the `--` cli arg by having launcher capture, ignore, and pass through all of the values after it, while only processing (and validating) the values before it updates text client and its components to allow for args to be passed through, captured in run_as_textclient, and used in parse_args if present * Update worlds/LauncherComponents.py Co-authored-by: Aaron Wagener * explicitly using default args for parse_args when launched directly * revert manual arg parsing by request * Update CommonClient.py * Update LauncherComponents.py * :) --------- Co-authored-by: Aaron Wagener Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> --- CommonClient.py | 4 ++-- Launcher.py | 5 ++++- worlds/LauncherComponents.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index 7f91172a..122de476 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -1035,7 +1035,7 @@ def run_as_textclient(*args): parser = get_base_parser(description="Gameless Archipelago Client, for text interfacing.") parser.add_argument('--name', default=None, help="Slot Name to connect as.") parser.add_argument("url", nargs="?", help="Archipelago connection url") - args = parser.parse_args(args if args else None) # this is necessary as long as CommonClient itself is launchable + args = parser.parse_args(args) if args.url: url = urllib.parse.urlparse(args.url) @@ -1053,4 +1053,4 @@ def run_as_textclient(*args): if __name__ == '__main__': logging.getLogger().setLevel(logging.INFO) # force log-level to work around log level resetting to WARNING - run_as_textclient() + run_as_textclient(*sys.argv[1:]) # default value for parse_args diff --git a/Launcher.py b/Launcher.py index 97903e2a..42f93547 100644 --- a/Launcher.py +++ b/Launcher.py @@ -401,7 +401,10 @@ if __name__ == '__main__': init_logging('Launcher') Utils.freeze_support() multiprocessing.set_start_method("spawn") # if launched process uses kivy, fork won't work - parser = argparse.ArgumentParser(description='Archipelago Launcher') + parser = argparse.ArgumentParser( + description='Archipelago Launcher', + usage="[-h] [--update_settings] [Patch|Game|Component] [-- component args here]" + ) run_group = parser.add_argument_group("Run") run_group.add_argument("--update_settings", action="store_true", help="Update host.yaml and exit.") diff --git a/worlds/LauncherComponents.py b/worlds/LauncherComponents.py index 4c64642a..fe6e44bb 100644 --- a/worlds/LauncherComponents.py +++ b/worlds/LauncherComponents.py @@ -61,7 +61,7 @@ class Component: processes = weakref.WeakSet() -def launch_subprocess(func: Callable, name: str = None, args: Tuple[str, ...] = ()): +def launch_subprocess(func: Callable, name: str = None, args: Tuple[str, ...] = ()) -> None: global processes import multiprocessing process = multiprocessing.Process(target=func, name=name, args=args) @@ -85,7 +85,7 @@ class SuffixIdentifier: def launch_textclient(*args): import CommonClient - launch_subprocess(CommonClient.run_as_textclient, "TextClient", args) + launch_subprocess(CommonClient.run_as_textclient, name="TextClient", args=args) def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, pathlib.Path]]: