Send a single command and print the result.
(api: SerialStudioAPI, args)
| 831 | |
| 832 | |
| 833 | def 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 | |
| 866 | def cmd_batch(api: SerialStudioAPI, args) -> int: |
no test coverage detected