// SPDX-License-Identifier: MIT // Copyright (C) 2026 Pooya Parsa // The CLI's --tailscale* flags as a net.tailscale spec (without the saved // state, which the CLI reads from --tailscale-state itself). Tailscale is // on only when a --tailscale* flag asks for it: TS_AUTHKEY in the // environment supplies the key then and never turns it on by itself (many // machines with Tailscale tooling export one). import type { TailscaleSpec } from "../core/devices.ts"; /** The flags that ask for Tailscale (any of them). */ export const TAILSCALE_FLAGS = ["tailscale", "tailscale-authkey", "tailscale-state", "tailscale-login-server", "tailscale-hostname", "tailscale-accept-routes", "tailscale-rewrite", "tailscale-exit-node"]; /** The spec for these arguments, or undefined when no --tailscale* flag is there. */ export function tailscaleArgs(args: readonly string[], env: Record): TailscaleSpec | undefined { if (!TAILSCALE_FLAGS.some((f) => args.includes(`--${f}`))) return undefined; const opt = (name: string) => { const i = args.indexOf(`--${name}`); return i >= 0 ? args[i + 1] : undefined; }; return { authKey: opt("tailscale-authkey") ?? (env.TS_AUTHKEY || undefined), controlURL: opt("tailscale-login-server"), hostname: opt("tailscale-hostname") ?? "unkernel", acceptRoutes: args.includes("--tailscale-accept-routes"), exitNode: opt("tailscale-exit-node") || undefined, guestAddress: !args.includes("--tailscale-rewrite"), }; }