|
6 | 6 | from .server import server |
7 | 7 | from .record import rec |
8 | 8 | from ..config import load_config, set_config |
| 9 | +from ..connection import Connection |
9 | 10 | from .. import __version__ |
10 | 11 |
|
11 | 12 |
|
| 13 | +def print_version(ctx, param, value): |
| 14 | + """Print version information for client and server.""" |
| 15 | + if not value or ctx.resilient_parsing: |
| 16 | + return |
| 17 | + |
| 18 | + click.echo(f"tvmux client version: {__version__}") |
| 19 | + |
| 20 | + # Try to get server version if running |
| 21 | + conn = Connection() |
| 22 | + if conn.is_running: |
| 23 | + try: |
| 24 | + api = conn.client() |
| 25 | + response = api.get("/version") |
| 26 | + if response.status_code == 200: |
| 27 | + server_version = response.json().get("version", "unknown") |
| 28 | + click.echo(f"tvmux server version: {server_version}") |
| 29 | + else: |
| 30 | + click.echo("tvmux server version: unable to retrieve") |
| 31 | + except Exception: |
| 32 | + click.echo("tvmux server version: error connecting") |
| 33 | + else: |
| 34 | + click.echo("tvmux server: not running") |
| 35 | + |
| 36 | + ctx.exit() |
| 37 | + |
| 38 | + |
12 | 39 | @click.group() |
13 | 40 | @click.option('--log-level', default='INFO', type=click.Choice(['DEBUG', 'INFO', 'WARNING', 'ERROR']), |
14 | 41 | help='Set logging level') |
15 | 42 | @click.option('--config-file', type=click.Path(exists=True), |
16 | 43 | help='Path to configuration file') |
17 | | -@click.version_option(version=__version__) |
| 44 | +@click.option('--version', is_flag=True, callback=print_version, |
| 45 | + expose_value=False, is_eager=True, help='Show version information') |
18 | 46 | def cli(log_level, config_file): |
19 | 47 | """Per-window recorder for tmux.""" |
20 | 48 | os.environ['TVMUX_LOG_LEVEL'] = log_level |
|
0 commit comments