MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / cmd_send

Function cmd_send

examples/API Test/test_api.py:833–863  ·  view source on GitHub ↗

Send a single command and print the result.

(api: SerialStudioAPI, args)

Source from the content-addressed store, hash-verified

831
832
833def cmd_send(api: SerialStudioAPI, args) -> int:
834 """Send a single command and print the result."""
835 params = None
836 if args.params:
837 try:
838 params = parse_params(args.params)
839 except ValueError as e:
840 print(f"[ERROR] {e}", file=sys.stderr)
841 return 1
842
843 response = api.send_command(args.command, params)
844
845 if response is None:
846 print("[ERROR] No response received", file=sys.stderr)
847 return 1
848
849 if args.json:
850 print(json.dumps(response, indent=2))
851 else:
852 if response.get("success"):
853 result = response.get("result", {})
854 if result:
855 print(json.dumps(result, indent=2))
856 else:
857 print("[OK] Command executed successfully")
858 else:
859 err = response.get("error", {})
860 print(f"[ERROR] {err.get('code')}: {err.get('message')}", file=sys.stderr)
861 return 1
862
863 return 0
864
865
866def cmd_batch(api: SerialStudioAPI, args) -> int:

Callers 1

mainFunction · 0.85

Calls 3

parse_paramsFunction · 0.85
send_commandMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected