mirror of
https://github.com/Ryujinx/Ryujinx-Mako.git
synced 2024-06-03 00:18:57 +02:00
Add small script to generate subcommand sections automatically
This commit is contained in:
parent
ed2a8fadda
commit
f48002636e
|
@ -11,6 +11,7 @@ except ImportError:
|
|||
|
||||
|
||||
class ConfigKey(StrEnum):
|
||||
DryRun = "MAKO_DRY_RUN"
|
||||
AppID = "MAKO_APP_ID"
|
||||
PrivateKey = "MAKO_PRIVATE_KEY"
|
||||
InstallationID = "MAKO_INSTALLATION_ID"
|
||||
|
@ -19,14 +20,23 @@ class ConfigKey(StrEnum):
|
|||
NAME = "Ryujinx-Mako"
|
||||
SCRIPT_NAME = NAME.lower().replace("-", "_")
|
||||
|
||||
# Check environment variables
|
||||
for key in ConfigKey:
|
||||
if key not in os.environ.keys() or len(os.environ[key]) == 0:
|
||||
raise KeyError(f"Required environment variable not set: {key}")
|
||||
if ConfigKey.DryRun not in os.environ.keys() or len(os.environ[ConfigKey.DryRun]) == 0:
|
||||
IS_DRY_RUN = False
|
||||
# Check environment variables
|
||||
for key in ConfigKey:
|
||||
if key == ConfigKey.DryRun:
|
||||
continue
|
||||
if key not in os.environ.keys() or len(os.environ[key]) == 0:
|
||||
raise KeyError(f"Required environment variable not set: {key}")
|
||||
|
||||
APP_ID = int(os.environ[ConfigKey.AppID])
|
||||
PRIVATE_KEY = os.environ[ConfigKey.PrivateKey]
|
||||
INSTALLATION_ID = int(os.environ[ConfigKey.InstallationID])
|
||||
APP_ID = int(os.environ[ConfigKey.AppID])
|
||||
PRIVATE_KEY = os.environ[ConfigKey.PrivateKey]
|
||||
INSTALLATION_ID = int(os.environ[ConfigKey.InstallationID])
|
||||
else:
|
||||
IS_DRY_RUN = True
|
||||
APP_ID = 0
|
||||
PRIVATE_KEY = ""
|
||||
INSTALLATION_ID = 0
|
||||
|
||||
GH_BOT_SUFFIX = "[bot]"
|
||||
GH_EMAIL_TEMPLATE = "{user_id}+{username}@users.noreply.github.com"
|
||||
|
|
|
@ -6,7 +6,8 @@ from typing import Any
|
|||
from github import Github
|
||||
from github.Auth import AppAuth
|
||||
|
||||
from ryujinx_mako._const import APP_ID, PRIVATE_KEY, INSTALLATION_ID, SCRIPT_NAME
|
||||
from ryujinx_mako._const import APP_ID, PRIVATE_KEY, INSTALLATION_ID, SCRIPT_NAME, \
|
||||
IS_DRY_RUN
|
||||
|
||||
|
||||
class Subcommand(ABC):
|
||||
|
@ -50,7 +51,7 @@ class Subcommand(ABC):
|
|||
class GithubSubcommand(Subcommand, ABC):
|
||||
_github = Github(
|
||||
auth=AppAuth(APP_ID, PRIVATE_KEY).get_installation_auth(INSTALLATION_ID)
|
||||
)
|
||||
) if not IS_DRY_RUN else None
|
||||
|
||||
@property
|
||||
def github(self):
|
||||
|
|
53
tools/generate_help.py
Executable file
53
tools/generate_help.py
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from typing import Union
|
||||
|
||||
|
||||
def run_mako_command(command: Union[str, list[str]]) -> str:
|
||||
subprocess_cmd = ["poetry", "run", "ryujinx-mako"]
|
||||
|
||||
if isinstance(command, str):
|
||||
subprocess_cmd.append(command)
|
||||
elif isinstance(command, list):
|
||||
subprocess_cmd.extend(command)
|
||||
else:
|
||||
raise TypeError(command)
|
||||
|
||||
env = os.environ.copy()
|
||||
env["MAKO_DRY_RUN"] = "1"
|
||||
|
||||
process = subprocess.run(
|
||||
subprocess_cmd, stdout=subprocess.PIPE, check=True, env=env
|
||||
)
|
||||
|
||||
return process.stdout.decode()
|
||||
|
||||
|
||||
def print_help(name: str, output: str, level=3):
|
||||
headline_prefix = "#" * level
|
||||
print(f"{headline_prefix} {name}\n")
|
||||
print("```")
|
||||
print(output.rstrip())
|
||||
print("```\n")
|
||||
|
||||
|
||||
general_help = run_mako_command("--help")
|
||||
for line in general_help.splitlines():
|
||||
subcommands = re.match(r" {2}\{(.+)}", line)
|
||||
if subcommands:
|
||||
break
|
||||
else:
|
||||
subcommands = None
|
||||
|
||||
if not subcommands:
|
||||
print("Could not find subcommands in general help output:")
|
||||
print(general_help)
|
||||
exit(1)
|
||||
|
||||
subcommands = subcommands.group(1).split(",")
|
||||
|
||||
print_help("Available commands", general_help, 2)
|
||||
for subcommand in subcommands:
|
||||
print_help(subcommand, run_mako_command([subcommand, "--help"]))
|
Loading…
Reference in New Issue
Block a user