Skip to content

Commit

Permalink
Launcher: explicitly handle cli arguments to be passed to the Compone…
Browse files Browse the repository at this point in the history
…nt (ArchipelagoMW#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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: NewSoupVi <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2024
1 parent d90cf0d commit 5021997
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ async def main(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)
Expand All @@ -1053,4 +1053,4 @@ async def main(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
5 changes: 4 additions & 1 deletion Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None):
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.")
Expand Down
4 changes: 2 additions & 2 deletions worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __repr__(self):
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)
Expand All @@ -85,7 +85,7 @@ def __call__(self, path: str) -> bool:

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]]:
Expand Down

0 comments on commit 5021997

Please sign in to comment.