(args: list[str])
| 1312 | |
| 1313 | |
| 1314 | def _cmd_config(args: list[str]) -> None: |
| 1315 | from uncommon_route.router.types import RoutingMode, Tier |
| 1316 | from uncommon_route.routing_config_store import RoutingConfigStore |
| 1317 | |
| 1318 | flags, rest = _parse_flags(args, {"json": False, "fallback": True, "strategy": True}) |
| 1319 | store = RoutingConfigStore() |
| 1320 | if not rest: |
| 1321 | rest = ["show"] |
| 1322 | |
| 1323 | sub = rest[0] |
| 1324 | output_json = bool(flags.get("json", False)) |
| 1325 | |
| 1326 | if sub == "show": |
| 1327 | _print_routing_config(store.export(), as_json=output_json) |
| 1328 | return |
| 1329 | |
| 1330 | if sub == "set-default-mode": |
| 1331 | if len(rest) < 2: |
| 1332 | print("Usage: uncommon-route config set-default-mode <mode>", file=sys.stderr) |
| 1333 | sys.exit(1) |
| 1334 | try: |
| 1335 | routing_mode = RoutingMode(rest[1].strip().lower()) |
| 1336 | except ValueError: |
| 1337 | print("Error: invalid mode", file=sys.stderr) |
| 1338 | sys.exit(1) |
| 1339 | payload = store.set_default_mode(routing_mode) |
| 1340 | _print_routing_config(payload, as_json=output_json) |
| 1341 | return |
| 1342 | |
| 1343 | if sub == "set-tier": |
| 1344 | if len(rest) < 4: |
| 1345 | print( |
| 1346 | "Usage: uncommon-route config set-tier <mode> <tier> <primary> [--fallback <csv>] [--strategy adaptive|hard-pin]", |
| 1347 | file=sys.stderr, |
| 1348 | ) |
| 1349 | sys.exit(1) |
| 1350 | try: |
| 1351 | routing_mode = RoutingMode(rest[1].strip().lower()) |
| 1352 | tier = Tier(rest[2].strip().upper()) |
| 1353 | except ValueError: |
| 1354 | print("Error: invalid mode or tier", file=sys.stderr) |
| 1355 | sys.exit(1) |
| 1356 | primary = rest[3].strip() |
| 1357 | fallback_csv = str(flags.get("fallback", rest[4] if len(rest) > 4 else "")) |
| 1358 | fallback = [part.strip() for part in fallback_csv.split(",") if part.strip()] |
| 1359 | strategy = str(flags.get("strategy", "adaptive")).strip().lower() |
| 1360 | if strategy not in {"adaptive", "hard-pin", "hard_pin", "pinned"}: |
| 1361 | print("Error: --strategy must be adaptive or hard-pin", file=sys.stderr) |
| 1362 | sys.exit(1) |
| 1363 | payload = store.set_tier( |
| 1364 | routing_mode, |
| 1365 | tier, |
| 1366 | primary=primary, |
| 1367 | fallback=fallback, |
| 1368 | hard_pin=strategy in {"hard-pin", "hard_pin", "pinned"}, |
| 1369 | ) |
| 1370 | _print_routing_config(payload, as_json=output_json) |
| 1371 | elif sub == "reset-tier": |
nothing calls this directly
no test coverage detected