MCPcopy
hub / github.com/wuyoscar/GPT-Image2-Skill / main

Function main

src/gpt_image_cli/cli.py:257–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

255
256
257def main() -> int:
258 args = parse_args()
259
260 _load_env_chain()
261 if "OPENAI_API_KEY" not in os.environ:
262 print(
263 "error: OPENAI_API_KEY not set. Add it to ~/.env or `export OPENAI_API_KEY=...`.",
264 file=sys.stderr,
265 )
266 return 2
267
268 if args.mask and not args.image:
269 print("error: --mask requires --image (edits endpoint only)", file=sys.stderr)
270 return 2
271
272 ext = args.output_format or "png"
273 out_path = Path(args.file).expanduser().resolve() if args.file else default_output_path(args.prompt, ext)
274
275 client = OpenAI() # auto-reads OPENAI_API_KEY
276
277 try:
278 result = call_edit(client, args) if args.image else call_generate(client, args)
279 except APIError as e:
280 print(f"error: {type(e).__name__}: {e}", file=sys.stderr)
281 return 1
282
283 data = result.data or []
284 if not data:
285 print(f"error: no image data in response: {result}", file=sys.stderr)
286 return 1
287
288 for p in write_outputs(data, out_path, args.n):
289 print(p)
290 return 0
291
292
293if __name__ == "__main__":

Callers 2

generate.pyFile · 0.90
cli.pyFile · 0.70

Calls 6

parse_argsFunction · 0.85
_load_env_chainFunction · 0.85
default_output_pathFunction · 0.85
call_editFunction · 0.85
call_generateFunction · 0.85
write_outputsFunction · 0.85

Tested by

no test coverage detected