mirror of
https://github.com/onyx-and-iris/q3rcon-cli.git
synced 2026-04-13 04:23:38 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 296b1eff3e | |||
| 26a00bff42 | |||
| 60afda97dc | |||
| 968cd2dc8a |
@@ -73,6 +73,7 @@ Usage: q3rcon-cli [OPTIONS] COMMAND
|
|||||||
|
|
||||||
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||||
┃ -i, --interactive Whether to start in interactive mode (defaults to false) ┃
|
┃ -i, --interactive Whether to start in interactive mode (defaults to false) ┃
|
||||||
|
┃ -v, --version Show the version and exit ┃
|
||||||
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
||||||
|
|
||||||
┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
┏━ Connection options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
||||||
|
|||||||
@@ -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.2.5'
|
__version__ = '0.3.0'
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from clypi import Command, Spinner, arg
|
|||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from . import console
|
from . import console
|
||||||
|
from .__about__ import __version__
|
||||||
from .commands import (
|
from .commands import (
|
||||||
Fastrestart,
|
Fastrestart,
|
||||||
Gametype,
|
Gametype,
|
||||||
@@ -57,9 +58,18 @@ class Q3rconCli(Command):
|
|||||||
short='i',
|
short='i',
|
||||||
help='Whether to start in interactive mode (defaults to false)',
|
help='Whether to start in interactive mode (defaults to false)',
|
||||||
)
|
)
|
||||||
|
version: bool = arg(
|
||||||
|
False,
|
||||||
|
short='v',
|
||||||
|
help='Show the version and exit',
|
||||||
|
)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
async def run(self):
|
async def run(self):
|
||||||
|
if self.version:
|
||||||
|
print(f'q3rcon-cli version: {clypi.style(__version__, fg="green")}')
|
||||||
|
return
|
||||||
|
|
||||||
if self.interactive:
|
if self.interactive:
|
||||||
await self.run_interactive()
|
await self.run_interactive()
|
||||||
else:
|
else:
|
||||||
@@ -68,7 +78,7 @@ class Q3rconCli(Command):
|
|||||||
async def run_interactive(self):
|
async def run_interactive(self):
|
||||||
print(
|
print(
|
||||||
clypi.style('Entering interactive mode. Type', fg='blue'),
|
clypi.style('Entering interactive mode. Type', fg='blue'),
|
||||||
clypi.style("'Q'", fg='red'),
|
clypi.style("'Q'", fg='yellow'),
|
||||||
clypi.style('to quit.', fg='blue'),
|
clypi.style('to quit.', fg='blue'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,14 +88,14 @@ class Q3rconCli(Command):
|
|||||||
if command.lower() == 'q':
|
if command.lower() == 'q':
|
||||||
break
|
break
|
||||||
|
|
||||||
TIMEOUTS = {
|
CMD_CONFIG = {
|
||||||
'status': (2, 1, False),
|
'status': (2, 1, False),
|
||||||
'fast_restart': (3, 1, True),
|
'fast_restart': (3, 1, True),
|
||||||
'map_restart': (3, 1, True),
|
'map_restart': (3, 1, True),
|
||||||
'map': (3, 1, True),
|
'map': (3, 1, True),
|
||||||
'map_rotate': (3, 1, True),
|
'map_rotate': (3, 1, True),
|
||||||
}
|
}
|
||||||
timeout, fragment_read_timeout, interpret = TIMEOUTS.get(
|
timeout, fragment_read_timeout, interpret = CMD_CONFIG.get(
|
||||||
command.split()[0].lower(),
|
command.split()[0].lower(),
|
||||||
(DEFAULT_TIMEOUT, DEFAULT_FRAGMENT_READ_TIMEOUT, False),
|
(DEFAULT_TIMEOUT, DEFAULT_FRAGMENT_READ_TIMEOUT, False),
|
||||||
)
|
)
|
||||||
@@ -95,19 +105,18 @@ class Q3rconCli(Command):
|
|||||||
self.host,
|
self.host,
|
||||||
self.port,
|
self.port,
|
||||||
self.password,
|
self.password,
|
||||||
timeout=timeout or DEFAULT_TIMEOUT,
|
timeout=timeout,
|
||||||
fragment_read_timeout=fragment_read_timeout
|
fragment_read_timeout=fragment_read_timeout,
|
||||||
or DEFAULT_FRAGMENT_READ_TIMEOUT,
|
|
||||||
) as client:
|
) as client:
|
||||||
try:
|
try:
|
||||||
if response := await client.send_command(
|
response = await client.send_command(
|
||||||
command, interpret=interpret
|
command, interpret=interpret
|
||||||
):
|
)
|
||||||
console.out.print_response(response)
|
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
console.err.print(
|
console.err.print(
|
||||||
f"Timeout waiting for response for command: '{command}'"
|
f"Timeout waiting for response for command: '{command}'"
|
||||||
)
|
)
|
||||||
|
console.out.print_response(response)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class OutConsole(Console):
|
|||||||
def print_response(self, response: str):
|
def print_response(self, response: str):
|
||||||
response = self._remove_colour_codes(response).removeprefix('print\n')
|
response = self._remove_colour_codes(response).removeprefix('print\n')
|
||||||
|
|
||||||
cprint(f'\n{response}\n', fg=self.style)
|
cprint(response, fg=self.style)
|
||||||
|
|
||||||
def print_status(self, response: str):
|
def print_status(self, response: str):
|
||||||
_slots = []
|
_slots = []
|
||||||
|
|||||||
Reference in New Issue
Block a user