Manage telemetry: status, enable, disable, show-sent, flush.
(args: list[str])
| 1914 | |
| 1915 | |
| 1916 | def _cmd_telemetry(args: list[str]) -> None: |
| 1917 | """Manage telemetry: status, enable, disable, show-sent, flush.""" |
| 1918 | from uncommon_route.telemetry import enable, disable, status, flush, get_sent_records |
| 1919 | sub = args[0] if args else "status" |
| 1920 | if sub == "status": |
| 1921 | s = status() |
| 1922 | state = "enabled" if s["enabled"] else "disabled" |
| 1923 | print(f" Telemetry: {state}") |
| 1924 | print(f" Pending records: {s['pending_records']}") |
| 1925 | print(f" Total sent: {s['total_sent']}") |
| 1926 | elif sub == "enable": |
| 1927 | enable() |
| 1928 | print(" Telemetry enabled.") |
| 1929 | elif sub == "disable": |
| 1930 | disable() |
| 1931 | print(" Telemetry disabled. Pending data discarded.") |
| 1932 | elif sub == "show-sent": |
| 1933 | records = get_sent_records() |
| 1934 | if not records: |
| 1935 | print(" No records sent yet.") |
| 1936 | else: |
| 1937 | for r in records[-20:]: |
| 1938 | print(json.dumps(r, ensure_ascii=False)) |
| 1939 | if len(records) > 20: |
| 1940 | print(f" ... ({len(records)} total, showing last 20)") |
| 1941 | elif sub == "flush": |
| 1942 | count = flush() |
| 1943 | print(f" Flushed {count} records.") |
| 1944 | else: |
| 1945 | print(f" Unknown telemetry command: {sub}") |
| 1946 | print(" Usage: uncommon-route telemetry [status|enable|disable|show-sent|flush]") |
| 1947 | |
| 1948 | |
| 1949 | def _cmd_explain(args: list[str]) -> None: |
nothing calls this directly
no test coverage detected