|
1 | 1 | """Command to launch the Parxy TUI.""" |
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | | -from typing import Annotated |
| 4 | +from typing import Annotated, Optional |
5 | 5 |
|
6 | 6 | import typer |
7 | 7 |
|
8 | 8 | from parxy_cli.console.console import Console |
9 | | -from parxy_cli.tui.app import run_tui |
10 | 9 |
|
11 | 10 | app = typer.Typer( |
12 | 11 | name='tui', help='Launch the Parxy TUI for interactive parser comparison' |
|
18 | 17 | @app.callback(invoke_without_command=True) |
19 | 18 | def tui( |
20 | 19 | workspace: Annotated[ |
21 | | - str, |
| 20 | + Optional[str], |
22 | 21 | typer.Argument( |
23 | | - help='Path to the workspace folder containing documents to process', |
| 22 | + help='Path to the workspace folder (optional — can be selected inside the TUI)', |
24 | 23 | ), |
25 | | - ], |
| 24 | + ] = None, |
26 | 25 | ): |
27 | 26 | """ |
28 | 27 | Launch the Parxy TUI for interactive parser comparison. |
29 | 28 |
|
| 29 | + If no workspace is provided, the TUI opens a folder selection screen. |
| 30 | +
|
30 | 31 | The TUI provides an interactive interface to: |
31 | 32 | - Browse files in your workspace |
32 | 33 | - Select multiple parsers to compare |
33 | 34 | - View parsing results side-by-side |
34 | 35 | - See JSON and Markdown diffs between parsers |
35 | 36 |
|
| 37 | + Requires the tui extra: pip install 'parxy[tui]' |
| 38 | +
|
36 | 39 | Examples: |
37 | 40 |
|
| 41 | + # Launch TUI and select a folder interactively |
| 42 | + parxy tui |
| 43 | +
|
38 | 44 | # Launch TUI with current directory |
39 | 45 | parxy tui . |
40 | 46 |
|
41 | 47 | # Launch TUI with specific folder |
42 | 48 | parxy tui /path/to/documents |
43 | 49 | """ |
44 | | - workspace_path = Path(workspace).resolve() |
| 50 | + workspace_path: Optional[Path] = None |
45 | 51 |
|
46 | | - if not workspace_path.exists(): |
47 | | - console.error(f'Workspace path does not exist: {workspace_path}') |
48 | | - raise typer.Exit(1) |
| 52 | + if workspace is not None: |
| 53 | + workspace_path = Path(workspace).resolve() |
49 | 54 |
|
50 | | - if not workspace_path.is_dir(): |
51 | | - console.error(f'Workspace path is not a directory: {workspace_path}') |
| 55 | + if not workspace_path.exists(): |
| 56 | + console.error(f'Workspace path does not exist: {workspace_path}') |
| 57 | + raise typer.Exit(1) |
| 58 | + |
| 59 | + if not workspace_path.is_dir(): |
| 60 | + console.error(f'Workspace path is not a directory: {workspace_path}') |
| 61 | + raise typer.Exit(1) |
| 62 | + |
| 63 | + try: |
| 64 | + from parxy_cli.tui.app import run_tui |
| 65 | + except ImportError: |
| 66 | + console.error( |
| 67 | + "The TUI requires the 'tui' extra. Install it with:\n\n" |
| 68 | + " pip install 'parxy[tui]'" |
| 69 | + ) |
52 | 70 | raise typer.Exit(1) |
53 | 71 |
|
54 | | - console.info(f'Starting Parxy TUI with workspace: {workspace_path}') |
| 72 | + if workspace_path: |
| 73 | + console.info(f'Starting Parxy TUI with workspace: {workspace_path}') |
55 | 74 |
|
56 | 75 | try: |
57 | 76 | run_tui(workspace_path) |
|
0 commit comments