List installed packages from manifest.json.
(
ctx: typer.Context,
path: Annotated[
Path,
typer.Argument(help="Unity project path"),
] = Path("."),
include_modules: Annotated[
bool,
typer.Option("--include-modules", help="Include Unity built-in modules"),
] = False,
json_flag: Annotated[
bool,
typer.Option("--json", help="Output as JSON"),
] = False,
)
| 144 | |
| 145 | @project_app.command("packages") |
| 146 | def project_packages( |
| 147 | ctx: typer.Context, |
| 148 | path: Annotated[ |
| 149 | Path, |
| 150 | typer.Argument(help="Unity project path"), |
| 151 | ] = Path("."), |
| 152 | include_modules: Annotated[ |
| 153 | bool, |
| 154 | typer.Option("--include-modules", help="Include Unity built-in modules"), |
| 155 | ] = False, |
| 156 | json_flag: Annotated[ |
| 157 | bool, |
| 158 | typer.Option("--json", help="Output as JSON"), |
| 159 | ] = False, |
| 160 | ) -> None: |
| 161 | """List installed packages from manifest.json.""" |
| 162 | context: CLIContext = ctx.obj |
| 163 | from unity_cli.hub.project import is_unity_project |
| 164 | |
| 165 | path = path.resolve() |
| 166 | |
| 167 | if not is_unity_project(path): |
| 168 | print_error(f"Not a valid Unity project: {path}", "INVALID_PROJECT") |
| 169 | raise typer.Exit(ExitCode.USAGE_ERROR) from None |
| 170 | |
| 171 | manifest_file = path / "Packages/manifest.json" |
| 172 | if not manifest_file.exists(): |
| 173 | print_error("manifest.json not found", "MANIFEST_NOT_FOUND") |
| 174 | raise typer.Exit(ExitCode.USAGE_ERROR) from None |
| 175 | |
| 176 | import json |
| 177 | |
| 178 | deps = json.loads(manifest_file.read_text(encoding="utf-8")).get("dependencies", {}) |
| 179 | packages = [ |
| 180 | {"name": n, "version": v, "local": v.startswith("file:")} |
| 181 | for n, v in sorted(deps.items()) |
| 182 | if include_modules or not n.startswith("com.unity.modules.") |
| 183 | ] |
| 184 | |
| 185 | if _should_json(context, json_flag): |
| 186 | print_json(packages) |
| 187 | else: |
| 188 | _print_manifest_packages(packages) |
| 189 | |
| 190 | |
| 191 | def _print_manifest_packages(packages: list[dict[str, Any]]) -> None: |
nothing calls this directly
no test coverage detected