MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / _capture

Function _capture

unity_cli/cli/commands/screenshot.py:90–143  ·  view source on GitHub ↗
(
    ctx: typer.Context,
    source: str,
    path: str | None,
    super_size: int,
    format: str,
    quality: int,
    width: int | None,
    height: int | None,
    camera_name: str | None,
    json_flag: bool,
)

Source from the content-addressed store, hash-verified

88
89
90def _capture(
91 ctx: typer.Context,
92 source: str,
93 path: str | None,
94 super_size: int,
95 format: str,
96 quality: int,
97 width: int | None,
98 height: int | None,
99 camera_name: str | None,
100 json_flag: bool,
101) -> None:
102 context: CLIContext = ctx.obj
103
104 if source not in ("game", "scene", "camera"):
105 print_error(f"Invalid source: {source}. Use 'game', 'scene', or 'camera'", "INVALID_SOURCE")
106 raise typer.Exit(ExitCode.USAGE_ERROR) from None
107
108 if format not in ("png", "jpg"):
109 print_error(f"Invalid format: {format}. Use 'png' or 'jpg'", "INVALID_FORMAT")
110 raise typer.Exit(ExitCode.USAGE_ERROR) from None
111
112 try:
113 result = context.client.screenshot.capture(
114 source=source, # type: ignore[arg-type]
115 path=path,
116 super_size=super_size,
117 width=width,
118 height=height,
119 camera=camera_name,
120 format=format, # type: ignore[arg-type]
121 quality=quality,
122 )
123
124 captured_path = result.get("path", "")
125
126 if _should_json(context, json_flag):
127 print_json(result)
128 return
129
130 if get_output_mode() is not OutputMode.PRETTY:
131 print(captured_path)
132 return
133
134 print_success(f"Screenshot captured: {captured_path}")
135 if result.get("note"):
136 print_line(f"[dim]{escape(str(result.get('note')))}[/dim]")
137 if result.get("camera"):
138 print_line(f"[dim]Camera: {escape(str(result.get('camera')))}[/dim]")
139 if result.get("format"):
140 print_line(f"[dim]Format: {escape(str(result.get('format')))}[/dim]")
141
142 except UnityCLIError as e:
143 _handle_error(e)
144
145
146def _burst(

Callers 1

screenshotFunction · 0.85

Calls 10

print_errorFunction · 0.90
_should_jsonFunction · 0.90
print_jsonFunction · 0.90
get_output_modeFunction · 0.90
print_successFunction · 0.90
print_lineFunction · 0.90
_handle_errorFunction · 0.90
ExitMethod · 0.80
captureMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected