Execute any Unity menu item by its menu-bar path. Works with: - Built-in menus: 'Edit/Play', 'File/Save', 'Assets/Refresh' - Package menus: 'Window/Package Manager', 'Window/Analysis/Profiler' - Custom tools: any [MenuItem("Path/To/Action")] defined in your project Use
(
ctx: typer.Context,
path: Annotated[str, typer.Argument(help="Menu item path (e.g., 'Edit/Play', 'Tools/MyCustomAction')")],
)
| 26 | |
| 27 | @menu_app.command("exec") |
| 28 | def menu_exec( |
| 29 | ctx: typer.Context, |
| 30 | path: Annotated[str, typer.Argument(help="Menu item path (e.g., 'Edit/Play', 'Tools/MyCustomAction')")], |
| 31 | ) -> None: |
| 32 | """Execute any Unity menu item by its menu-bar path. |
| 33 | |
| 34 | Works with: |
| 35 | - Built-in menus: 'Edit/Play', 'File/Save', 'Assets/Refresh' |
| 36 | - Package menus: 'Window/Package Manager', 'Window/Analysis/Profiler' |
| 37 | - Custom tools: any [MenuItem("Path/To/Action")] defined in your project |
| 38 | |
| 39 | Use 'u menu list' (optionally with --filter) to discover available menu paths. |
| 40 | |
| 41 | Examples: |
| 42 | u menu exec 'Edit/Play' |
| 43 | u menu exec 'Assets/Refresh' |
| 44 | u menu exec 'Window/Rendering/Lighting' |
| 45 | u menu exec 'Tools/RegenerateData' # custom [MenuItem] |
| 46 | """ |
| 47 | context: CLIContext = ctx.obj |
| 48 | try: |
| 49 | result = context.client.menu.execute(path) |
| 50 | if result.get("success"): |
| 51 | print_success(result.get("message", f"Executed: {path}")) |
| 52 | else: |
| 53 | print_error(result.get("message", f"Failed: {path}")) |
| 54 | raise typer.Exit(ExitCode.OPERATION_ERROR) from None |
| 55 | except UnityCLIError as e: |
| 56 | _handle_error(e) |
| 57 | |
| 58 | |
| 59 | @menu_app.command("list") |
nothing calls this directly
no test coverage detected