mirror of
https://github.com/tcsenpai/UWINE.git
synced 2025-06-07 12:05:21 +00:00
gamelauncher.py: update parse_args
- Reimplement parse_args to simply return a single positional argument string or a Namespace object. As a result the new usage will be: $ gamelauncher.py /home/foo/foo.exe $ gamelauncher.py /home/foo/foo.exe -opengl ... $ gamelauncher.py --config example.toml - Everything following the program will be interpreted as a single positional argument and this removes the need for quotes for the envvar usage. The optional arguments: --exe, --options, --store and --verb will no longer be supported.
This commit is contained in:
parent
fc91d60e65
commit
d0dbe23663
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
from argparse import ArgumentParser, _ArgumentGroup, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import tomllib
|
import tomllib
|
||||||
from typing import Dict, Any, List, Set
|
from typing import Dict, Any, List, Set, Union
|
||||||
import gamelauncher_plugins
|
import gamelauncher_plugins
|
||||||
from re import match
|
from re import match
|
||||||
|
|
||||||
@ -14,57 +14,35 @@ from re import match
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def parse_args() -> Namespace: # noqa: D103
|
def parse_args() -> Union[Namespace, str]: # noqa: D103
|
||||||
stores: List[str] = [
|
opt_args: Set[str] = {"--help", "-h", "--config"}
|
||||||
"amazon",
|
|
||||||
"battlenet",
|
|
||||||
"ea",
|
|
||||||
"egs",
|
|
||||||
"gog",
|
|
||||||
"humble",
|
|
||||||
"itchio",
|
|
||||||
"ubisoft",
|
|
||||||
]
|
|
||||||
exe: str = Path(__file__).name
|
exe: str = Path(__file__).name
|
||||||
usage: str = """
|
usage: str = f"""
|
||||||
example usage:
|
example usage:
|
||||||
{} --config example.toml
|
WINEPREFIX= GAMEID= PROTONPATH= {exe} /home/foo/example.exe
|
||||||
{} --config /home/foo/example.toml --options '-opengl'
|
WINEPREFIX= GAMEID= PROTONPATH= {exe} /home/foo/example.exe -opengl
|
||||||
WINEPREFIX= GAMEID= PROTONPATH= {} --exe /home/foo/example.exe --options '-opengl'
|
WINEPREFIX= GAMEID= PROTONPATH= {exe} ""
|
||||||
WINEPREFIX= GAMEID= PROTONPATH= {} --exe /home/foo/example.exe --store gog
|
WINEPREFIX= GAMEID= PROTONPATH= PROTON_VERB= {exe} /home/foo/example.exe
|
||||||
WINEPREFIX= GAMEID= PROTONPATH= {} --exe ""
|
WINEPREFIX= GAMEID= PROTONPATH= STORE= {exe} /home/foo/example.exe
|
||||||
WINEPREFIX= GAMEID= PROTONPATH= {} --exe /home/foo/example.exe --verb waitforexitandrun
|
{exe} --config /home/foo/example.toml
|
||||||
""".format(exe, exe, exe, exe, exe, exe)
|
"""
|
||||||
|
|
||||||
parser: ArgumentParser = argparse.ArgumentParser(
|
parser: ArgumentParser = argparse.ArgumentParser(
|
||||||
description="Unified Linux Wine Game Launcher",
|
description="Unified Linux Wine Game Launcher",
|
||||||
epilog=usage,
|
epilog=usage,
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
)
|
)
|
||||||
group: _ArgumentGroup = parser.add_mutually_exclusive_group(required=True)
|
parser.add_argument("--config", help="path to TOML file")
|
||||||
group.add_argument("--config", help="path to TOML file")
|
|
||||||
group.add_argument(
|
|
||||||
"--exe",
|
|
||||||
help="path to game executable\npass an empty string to create a prefix",
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--verb",
|
|
||||||
help="a verb to pass to Proton (default: waitforexitandrun)",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--options",
|
|
||||||
help="launch options for game executable\nNOTE: options must be wrapped in quotes",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--store",
|
|
||||||
help=f"the store of the game executable\nNOTE: will override the store specified in config\nexamples: {stores}",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
if not sys.argv[1:]:
|
||||||
|
err: str = "Please see project README.md for more info and examples.\nhttps://github.com/Open-Wine-Components/ULWGL-launcher"
|
||||||
|
parser.print_help()
|
||||||
|
raise SystemExit(err)
|
||||||
|
|
||||||
|
if sys.argv[1:][0] in opt_args:
|
||||||
return parser.parse_args(sys.argv[1:])
|
return parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
def _setup_pfx(path: str) -> None:
|
def _setup_pfx(path: str) -> None:
|
||||||
|
return sys.argv[1:][0]
|
||||||
"""Create a symlink to the WINE prefix and tracked_files file."""
|
"""Create a symlink to the WINE prefix and tracked_files file."""
|
||||||
if not (Path(path + "/pfx")).expanduser().is_symlink():
|
if not (Path(path + "/pfx")).expanduser().is_symlink():
|
||||||
# When creating the symlink, we want it to be in expanded form when passed unexpanded paths
|
# When creating the symlink, we want it to be in expanded form when passed unexpanded paths
|
||||||
|
Loading…
x
Reference in New Issue
Block a user