diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..503b59d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: + - repo: local + hooks: + - id: update-readme + name: update-readme + entry: python tools/update_readme_help.py + language: python + pass_filenames: false diff --git a/README.md b/README.md index 09d9e2d..fd0a986 100644 --- a/README.md +++ b/README.md @@ -59,26 +59,26 @@ export Q3RCON_CLI_PASSWORD="" ```console Usage: q3rcon-cli [OPTIONS] COMMAND -┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ -┃ status Prints the status of the server ┃ -┃ mapname Prints the current map name of the server ┃ -┃ maprotate Rotates the map to the next one in the map rotation list ┃ -┃ fastrestart Executes a fast restart of the server ┃ -┃ gametype Get or set the current gametype of the server ┃ -┃ hostname Get or set the current hostname of the server ┃ -┃ map Get the current map or change to a new one ┃ -┃ plugins Prints the currently loaded plugins of the server ┃ -┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ status Prints the status of the server ┃ +┃ mapname Prints the current map name of the server ┃ +┃ maprotate Rotates the map to the next one in the map rotation list ┃ +┃ fastrestart Executes a fast restart of the server ┃ +┃ gametype Get or set the current gametype of the server ┃ +┃ hostname Get or set the current hostname of the server ┃ +┃ map Get the current map or change to a new one ┃ +┃ plugins Prints the currently loaded plugins of the server ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ -┃ -i, --interactive Whether to start in interactive mode (defaults to false) ┃ -┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ -i, --interactive Whether to start in interactive mode (defaults to false) ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ -┃ -h, --host The host to connect to ┃ -┃ -p, --port The port to connect to ┃ -┃ -P, --password The password for authentication ┃ -┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ -h, --host The host to connect to ┃ +┃ -p, --port The port to connect to ┃ +┃ -P, --password The password for authentication ┃ +┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ``` ## Special Thanks diff --git a/tools/update_readme_help.py b/tools/update_readme_help.py new file mode 100644 index 0000000..dfeaee2 --- /dev/null +++ b/tools/update_readme_help.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +import re +import subprocess +from pathlib import Path + +REPO_ROOT = Path(__file__).parent.parent +README_PATH = REPO_ROOT / 'README.md' +HELP_CMD = ['hatch', 'run', 'q3rcon-cli', '--help'] + + +def get_help_output(): + result = subprocess.run(HELP_CMD, capture_output=True, text=True, check=True) + output = result.stdout.strip() + ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') + output = ansi_escape.sub('', output) + return output + + +def update_readme(help_text): + readme = README_PATH.read_text() + + pattern = re.compile( + r'```console\nUsage: q3rcon-cli \[OPTIONS\] COMMAND.*?```', re.DOTALL + ) + new_block = f'```console\n{help_text}\n```' + new_readme, n = pattern.subn(new_block, readme, count=1) + if n == 0: + raise RuntimeError( + 'Could not find the q3rcon-cli usage console block to replace in README.md' + ) + README_PATH.write_text(new_readme) + print('README.md updated with latest --help output.') + + +def main(): + help_text = get_help_output() + update_readme(help_text) + + +if __name__ == '__main__': + main()