(args: list[str])
| 941 | |
| 942 | |
| 943 | def _cmd_init(args: list[str]) -> None: |
| 944 | from uncommon_route.providers import KNOWN_BASE_URLS, add_provider, load_providers |
| 945 | from uncommon_route.tui.i18n import SUPPORTED_LANGS |
| 946 | from uncommon_route.tui.i18n import t as translate |
| 947 | |
| 948 | flags, _ = _parse_flags(args, {"port": True, "tui": False, "lang": True}) |
| 949 | port = int(flags.get("port", 8403)) |
| 950 | |
| 951 | if flags.get("tui") or os.environ.get("UNCOMMON_ROUTE_TUI") == "1": |
| 952 | try: |
| 953 | from uncommon_route.tui.init_app import run_init_tui |
| 954 | except ImportError: |
| 955 | print(" ! Textual is not installed. Install the optional extra:", file=sys.stderr) |
| 956 | print(" pip install 'uncommon-route[tui]'", file=sys.stderr) |
| 957 | sys.exit(1) |
| 958 | |
| 959 | rc_display, rc_path = _detect_rc_path() |
| 960 | |
| 961 | def _render(client: str, port: int) -> list[str]: |
| 962 | return _render_client_exports(client, port=port) |
| 963 | |
| 964 | run_init_tui( |
| 965 | rc_path=rc_path, |
| 966 | rc_display=rc_display, |
| 967 | render_exports=_render, |
| 968 | start_background_proxy=_start_background_proxy, |
| 969 | port=port, |
| 970 | ) |
| 971 | return |
| 972 | |
| 973 | prompter = TerminalPrompter() |
| 974 | store = ConnectionsStore() |
| 975 | |
| 976 | # Step 0 — language. --lang flag short-circuits the picker (handy for CI/scripts). |
| 977 | lang_flag = str(flags.get("lang", "")).strip().lower() |
| 978 | if lang_flag in SUPPORTED_LANGS: |
| 979 | lang = lang_flag |
| 980 | else: |
| 981 | _print_init_logo("UncommonRoute · local llm router") |
| 982 | try: |
| 983 | lang = _pick_init_language(prompter) |
| 984 | except KeyboardInterrupt: |
| 985 | print() |
| 986 | print(" Setup cancelled.") |
| 987 | sys.exit(130) |
| 988 | |
| 989 | def t(key: str, **fmt: object) -> str: |
| 990 | return translate(key, lang, **fmt) |
| 991 | |
| 992 | if lang_flag in SUPPORTED_LANGS: |
| 993 | # When language was passed via --lang we still owe the user a logo + intro. |
| 994 | _print_init_logo(t("splash.subtitle")) |
| 995 | |
| 996 | print(f" {_c(t('cli.title'), _ANSI_BOLD)}") |
| 997 | print(f" {_c('─' * 50, _ANSI_DIM)}") |
| 998 | print(f" {t('cli.intro')}") |
| 999 | print() |
| 1000 |
nothing calls this directly
no test coverage detected