mirror of
https://github.com/onyx-and-iris/q3rcon-cli.git
synced 2026-04-13 04:23:38 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dd7f9775f2 | |||
| 36e54e89b7 | |||
| 84702a5360 | |||
| 7ec51293e4 | |||
| 0e962e5aa0 |
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
|
||||||
41
README.md
41
README.md
@@ -49,8 +49,8 @@ example .envrc:
|
|||||||
```env
|
```env
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
export Q3RCON_CLI_HOST="localhost"
|
export Q3RCON_CLI_HOST=localhost
|
||||||
export Q3RCON_CLI_PORT="28960"
|
export Q3RCON_CLI_PORT=28960
|
||||||
export Q3RCON_CLI_PASSWORD="<rcon password>"
|
export Q3RCON_CLI_PASSWORD="<rcon password>"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -59,26 +59,27 @@ export Q3RCON_CLI_PASSWORD="<rcon password>"
|
|||||||
```console
|
```console
|
||||||
Usage: q3rcon-cli [OPTIONS] COMMAND
|
Usage: q3rcon-cli [OPTIONS] COMMAND
|
||||||
|
|
||||||
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||||
┃ status Prints the status of the server ┃
|
┃ fastrestart Executes a fast restart of the server ┃
|
||||||
┃ mapname Prints the current map name of the server ┃
|
┃ gametype Get or set the current gametype of the server ┃
|
||||||
┃ maprotate Rotates the map to the next one in the map rotation list ┃
|
┃ hostname Get or set the current hostname of the server ┃
|
||||||
┃ fastrestart Executes a fast restart of the server ┃
|
┃ map Get the current map or change to a new one ┃
|
||||||
┃ gametype Get or set the current gametype of the server ┃
|
┃ mapname Prints the current map name of the server ┃
|
||||||
┃ hostname Get or set the current hostname of the server ┃
|
┃ maprestart Restarts the current map ┃
|
||||||
┃ map Get the current map or change to a new one ┃
|
┃ maprotate Rotates the map to the next one in the map rotation list ┃
|
||||||
┃ plugins Prints the currently loaded plugins of the server ┃
|
┃ plugins Prints the currently loaded plugins of the server ┃
|
||||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
┃ status Prints the status of the server ┃
|
||||||
|
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||||
|
|
||||||
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||||
┃ -i, --interactive Whether to start in interactive mode (defaults to false) ┃
|
┃ -i, --interactive Whether to start in interactive mode (defaults to false) ┃
|
||||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||||
|
|
||||||
┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||||
┃ -h, --host <HOST> The host to connect to ┃
|
┃ -h, --host <HOST> The host to connect to ┃
|
||||||
┃ -p, --port <PORT> The port to connect to ┃
|
┃ -p, --port <PORT> The port to connect to ┃
|
||||||
┃ -P, --password <PASSWORD> The password for authentication ┃
|
┃ -P, --password <PASSWORD> The password for authentication ┃
|
||||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||||
```
|
```
|
||||||
|
|
||||||
## Special Thanks
|
## Special Thanks
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2026-present onyx-and-iris <code@onyxandiris.online>
|
# SPDX-FileCopyrightText: 2026-present onyx-and-iris <code@onyxandiris.online>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
__version__ = "0.1.0"
|
__version__ = '0.2.0'
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from .commands import (
|
|||||||
Hostname,
|
Hostname,
|
||||||
Map,
|
Map,
|
||||||
Mapname,
|
Mapname,
|
||||||
|
Maprestart,
|
||||||
Maprotate,
|
Maprotate,
|
||||||
Plugins,
|
Plugins,
|
||||||
Status,
|
Status,
|
||||||
@@ -16,7 +17,15 @@ from .commands import (
|
|||||||
from .console import Console
|
from .console import Console
|
||||||
|
|
||||||
Subcommands = (
|
Subcommands = (
|
||||||
Status | Mapname | Maprotate | Fastrestart | Gametype | Hostname | Map | Plugins
|
Fastrestart
|
||||||
|
| Gametype
|
||||||
|
| Hostname
|
||||||
|
| Map
|
||||||
|
| Mapname
|
||||||
|
| Maprestart
|
||||||
|
| Maprotate
|
||||||
|
| Plugins
|
||||||
|
| Status
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +63,7 @@ class Q3rconCli(Command):
|
|||||||
if self.interactive:
|
if self.interactive:
|
||||||
await self.run_interactive()
|
await self.run_interactive()
|
||||||
else:
|
else:
|
||||||
await Status.run(self)
|
await Status(self.host, self.port, self.password).run()
|
||||||
|
|
||||||
async def run_interactive(self):
|
async def run_interactive(self):
|
||||||
print(
|
print(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from .gametype import Gametype
|
|||||||
from .hostname import Hostname
|
from .hostname import Hostname
|
||||||
from .map import Map
|
from .map import Map
|
||||||
from .mapname import Mapname
|
from .mapname import Mapname
|
||||||
|
from .maprestart import Maprestart
|
||||||
from .maprotate import Maprotate
|
from .maprotate import Maprotate
|
||||||
from .plugins import Plugins
|
from .plugins import Plugins
|
||||||
from .status import Status
|
from .status import Status
|
||||||
@@ -16,4 +17,5 @@ __all__ = [
|
|||||||
'Hostname',
|
'Hostname',
|
||||||
'Map',
|
'Map',
|
||||||
'Plugins',
|
'Plugins',
|
||||||
|
'Maprestart',
|
||||||
]
|
]
|
||||||
|
|||||||
22
src/q3rcon_cli/commands/maprestart.py
Normal file
22
src/q3rcon_cli/commands/maprestart.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from aioq3rcon import Client
|
||||||
|
from clypi import Command, Spinner, arg
|
||||||
|
from typing_extensions import override
|
||||||
|
|
||||||
|
from q3rcon_cli.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
class Maprestart(Command):
|
||||||
|
"""Restarts the current map."""
|
||||||
|
|
||||||
|
host: str = arg(inherited=True)
|
||||||
|
port: int = arg(inherited=True)
|
||||||
|
password: str = arg(inherited=True)
|
||||||
|
|
||||||
|
@override
|
||||||
|
async def run(self):
|
||||||
|
async with Spinner('Restarting map...'):
|
||||||
|
async with Client(
|
||||||
|
self.host, self.port, self.password, fragment_read_timeout=1
|
||||||
|
) as client:
|
||||||
|
if response := await client.send_command('map_restart'):
|
||||||
|
Console.print_response(response)
|
||||||
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()
|
||||||
Reference in New Issue
Block a user