Skip to content

Commit

Permalink
adds handling for the -- cli arg by having launcher capture, ignore…
Browse files Browse the repository at this point in the history
…, 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
  • Loading branch information
qwint committed Jul 30, 2024
1 parent 77e3f9f commit 20628b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ def get_base_parser(description: typing.Optional[str] = None):
return parser


def run_as_textclient():
def run_as_textclient(*args):
class TextContext(CommonContext):
# Text Mode to use !hint and such with games that have no text entry
tags = CommonContext.tags | {"TextOnly"}
Expand Down Expand Up @@ -1033,7 +1033,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 = parser.parse_args(args if args else None)

if args.url:
url = urllib.parse.urlparse(args.url)
Expand Down
21 changes: 17 additions & 4 deletions Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,28 @@ 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.")
run_group.add_argument("Patch|Game|Component", type=str, nargs="?",
help="Pass either a patch file, a generated game or the name of a component to run.")
run_group.add_argument("args", nargs="*",
help="Arguments to pass to component.")
main(parser.parse_args())
run_group.add_argument("--",
help="Arguments to pass to component.",
dest="args", default=[])
args = sys.argv[1:]
if "--" in args:
i = args.index("--")
passthrough_args = args[i+1:]
args = args[:i]
args = parser.parse_args(args)
args.args = passthrough_args
else:
args = parser.parse_args()
main(args)

from worlds.LauncherComponents import processes
for process in processes:
Expand Down
8 changes: 4 additions & 4 deletions worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __repr__(self):
processes = weakref.WeakSet()


def launch_subprocess(func: Callable, name: str = None):
def launch_subprocess(func: Callable, name: str = None, args=()):
global processes
import multiprocessing
process = multiprocessing.Process(target=func, name=name)
process = multiprocessing.Process(target=func, name=name, args=args)
process.start()
processes.add(process)

Expand All @@ -78,9 +78,9 @@ def __call__(self, path: str) -> bool:
return False


def launch_textclient():
def launch_textclient(*args):
import CommonClient
launch_subprocess(CommonClient.run_as_textclient, name="TextClient")
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 20628b8

Please sign in to comment.