Find the project root by walking up from CWD. Checks global settings first (more fundamental), then project settings. Exits with code 1 if either check fails.
()
| 77 | |
| 78 | |
| 79 | def require_project_root() -> Path: |
| 80 | """Find the project root by walking up from CWD. |
| 81 | |
| 82 | Checks global settings first (more fundamental), then project settings. |
| 83 | Exits with code 1 if either check fails. |
| 84 | """ |
| 85 | gs_path = user_settings_path() |
| 86 | if not gs_path.is_file(): |
| 87 | _typer.echo( |
| 88 | f"Error: Global settings not found: {format_path_for_display(gs_path)}\n" |
| 89 | "Run `ccc init` to create it with default settings.", |
| 90 | err=True, |
| 91 | ) |
| 92 | raise _typer.Exit(code=1) |
| 93 | root = find_project_root(Path.cwd()) |
| 94 | if root is None: |
| 95 | _typer.echo( |
| 96 | "Error: Not in an initialized project directory.\n" |
| 97 | "Run `ccc init` in your project root to get started.", |
| 98 | err=True, |
| 99 | ) |
| 100 | raise _typer.Exit(code=1) |
| 101 | return root |
| 102 | |
| 103 | |
| 104 | _F = TypeVar("_F", bound=Callable[..., object]) |