mirror of
https://github.com/onyx-and-iris/q3rcon-cli.git
synced 2026-03-23 18:29:18 +00:00
add pre-commit config + update readme script
This commit is contained in:
parent
7ec51293e4
commit
84702a5360
8
.pre-commit-config.yaml
Normal file
8
.pre-commit-config.yaml
Normal file
@ -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
|
||||
36
README.md
36
README.md
@ -59,26 +59,26 @@ export Q3RCON_CLI_PASSWORD="<rcon 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 <HOST> The host to connect to ┃
|
||||
┃ -p, --port <PORT> The port to connect to ┃
|
||||
┃ -P, --password <PASSWORD> The password for authentication ┃
|
||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||
┃ -h, --host <HOST> The host to connect to ┃
|
||||
┃ -p, --port <PORT> The port to connect to ┃
|
||||
┃ -P, --password <PASSWORD> The password for authentication ┃
|
||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||
```
|
||||
|
||||
## Special Thanks
|
||||
|
||||
41
tools/update_readme_help.py
Normal file
41
tools/update_readme_help.py
Normal file
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user