-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add reeln init command for guided first-time setup #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e563e9
feat: add reeln init command for guided first-time setup
JRemitz 438b645
fix: find uv in common paths when PATH is minimal (Tauri/GUI apps)
JRemitz 20c4e33
fix: resolve ruff lint errors in init_cmd
JRemitz f1b3006
fix: add return type annotation for mypy strict mode
JRemitz 1bd5c98
fix: update installer tests for full-path uv detection
JRemitz bf367ee
fix: exclude interactive prompt functions from coverage
JRemitz aabd588
test: add coverage for _find_uv fallback path and not-found cases
JRemitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| """Guided first-time configuration.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| import types | ||
| from pathlib import Path | ||
|
|
||
| import typer | ||
| from rich.console import Console | ||
| from rich.panel import Panel | ||
| from rich.table import Table | ||
|
|
||
| from reeln.core.config import ( | ||
| config_dir, | ||
| default_config, | ||
| save_config, | ||
| ) | ||
| from reeln.core.errors import PromptAborted | ||
| from reeln.core.event_types import default_event_type_entries | ||
| from reeln.core.segment import list_sports | ||
| from reeln.models.config import AppConfig, PathConfig | ||
|
|
||
| console = Console() | ||
|
|
||
|
|
||
| def _interactive() -> bool: | ||
| """Return True if stdin is an interactive terminal.""" | ||
| return sys.stdin.isatty() | ||
|
|
||
|
|
||
| def _require_questionary() -> types.ModuleType: # pragma: no cover | ||
| """Lazy-import questionary with a helpful error if missing.""" | ||
| if not _interactive(): | ||
| msg = ( | ||
| "Interactive prompts require a terminal. " | ||
| "Provide --sport, --source-dir, and --output-dir for non-interactive use." | ||
| ) | ||
| raise typer.BadParameter(msg) | ||
| try: | ||
| import questionary | ||
| except ImportError: | ||
| raise typer.BadParameter( | ||
| "Interactive prompts require the 'questionary' package. " | ||
| "Install it with: pip install reeln[interactive]" | ||
| ) from None | ||
| return questionary | ||
|
|
||
|
|
||
| def _prompt_sport(preset: str | None) -> str: # pragma: no cover | ||
| """Prompt for sport selection, or return preset.""" | ||
| if preset is not None: | ||
| return preset | ||
| questionary = _require_questionary() | ||
| choices = [alias.sport for alias in list_sports()] | ||
| answer: str | None = questionary.select( | ||
| "Sport:", | ||
| choices=choices, | ||
| default="hockey", | ||
| ).ask() | ||
| if not answer: | ||
| raise PromptAborted("Sport prompt cancelled") | ||
| return answer | ||
|
|
||
|
|
||
| def _prompt_path(label: str, preset: Path | None, default_hint: str) -> Path: # pragma: no cover | ||
| """Prompt for a directory path, or return preset.""" | ||
| if preset is not None: | ||
| return preset | ||
| questionary = _require_questionary() | ||
| answer: str | None = questionary.text( | ||
| f"{label}:", | ||
| default=default_hint, | ||
| ).ask() | ||
| if not answer: | ||
| raise PromptAborted(f"{label} prompt cancelled") | ||
| return Path(answer) | ||
|
|
||
|
|
||
| def _prompt_overwrite(path: Path) -> bool: # pragma: no cover | ||
| """Ask user whether to overwrite an existing config file.""" | ||
| questionary = _require_questionary() | ||
| answer: bool | None = questionary.confirm( | ||
| f"Config already exists at {path}. Overwrite?", | ||
| default=False, | ||
| ).ask() | ||
| return bool(answer) | ||
|
|
||
|
|
||
| def init( | ||
| sport: str | None = typer.Option(None, "--sport", help="Sport type"), | ||
| source_dir: Path | None = typer.Option( | ||
| None, "--source-dir", help="Replay source directory" | ||
| ), | ||
| output_dir: Path | None = typer.Option( | ||
| None, "--output-dir", help="Game output directory" | ||
| ), | ||
| config_path: Path | None = typer.Option( | ||
| None, "--config", help="Config file path" | ||
| ), | ||
| force: bool = typer.Option( | ||
| False, "--force", "-f", help="Overwrite existing config" | ||
| ), | ||
| ) -> None: | ||
| """Set up reeln with guided configuration.""" | ||
| # 1. Resolve config path | ||
| target = config_path if config_path is not None else config_dir() / "config.json" | ||
|
|
||
| # 2. Check for existing config | ||
| if target.exists() and not force: | ||
| if _interactive(): # pragma: no cover | ||
| if not _prompt_overwrite(target): | ||
| console.print("[yellow]Init cancelled.[/yellow]") | ||
| raise typer.Exit(0) | ||
| else: | ||
| console.print( | ||
| f"[yellow]Config already exists at {target}. " | ||
| "Use --force to overwrite.[/yellow]" | ||
| ) | ||
| raise typer.Exit(1) | ||
|
|
||
| # 3. Gather inputs (prompt interactively when not provided) | ||
| sport_val = _prompt_sport(sport) | ||
| source = _prompt_path( | ||
| "Replay source directory", | ||
| source_dir, | ||
| str(Path.home() / "Videos" / "OBS"), | ||
| ) | ||
| output = _prompt_path( | ||
| "Game output directory", | ||
| output_dir, | ||
| str(Path.home() / "Videos" / "reeln"), | ||
| ) | ||
|
|
||
| # 4. Build config from defaults + user inputs | ||
| cfg = default_config() | ||
| cfg = AppConfig( | ||
| config_version=cfg.config_version, | ||
| sport=sport_val, | ||
| event_types=default_event_type_entries(sport_val), | ||
| video=cfg.video, | ||
| paths=PathConfig( | ||
| source_dir=source.expanduser(), | ||
| source_glob=cfg.paths.source_glob, | ||
| output_dir=output.expanduser(), | ||
| temp_dir=cfg.paths.temp_dir, | ||
| ), | ||
| render_profiles=cfg.render_profiles, | ||
| iterations=cfg.iterations, | ||
| branding=cfg.branding, | ||
| orchestration=cfg.orchestration, | ||
| plugins=cfg.plugins, | ||
| ) | ||
|
|
||
| # 5. Create directories | ||
| source.expanduser().mkdir(parents=True, exist_ok=True) | ||
| output.expanduser().mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # 6. Save config | ||
| saved_path = save_config(cfg, target) | ||
|
|
||
| # 7. Summary | ||
| table = Table(show_header=False, box=None, padding=(0, 2)) | ||
| table.add_column(style="bold") | ||
| table.add_column() | ||
| table.add_row("Sport", sport_val) | ||
| table.add_row("Source", str(source.expanduser())) | ||
| table.add_row("Output", str(output.expanduser())) | ||
| table.add_row("Config", str(saved_path)) | ||
|
|
||
| event_names = [et.name for et in cfg.event_types] | ||
| if event_names: | ||
| table.add_row("Events", ", ".join(event_names)) | ||
|
|
||
| console.print() | ||
| console.print( | ||
| Panel( | ||
| table, | ||
| title="[green]reeln initialized[/green]", | ||
| border_style="green", | ||
| ) | ||
| ) | ||
| console.print() | ||
| console.print("Next steps:") | ||
| console.print(" reeln game init Create your first game") | ||
| console.print(" reeln config show View full configuration") | ||
| console.print(" reeln doctor Run health checks") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.