import { version } from "../../package.js";
import { ROOT_COMMAND_DESCRIPTION } from "./command-manifest.js";
import { isGatewayRunFastPathArgv } from "./gateway-run-argv.js";
import { createDefaultContext } from "./registry.js";
//#region src/cli/gateway-run-fast-path.ts
let parsedOpts = {};
function getContextWithOpts(argv = process.argv) {
	return createDefaultContext(argv, parsedOpts);
}
function buildGatewayRunOptions(cmd) {
	return cmd.description("Start the xopc gateway server").option("--bind <mode>", "Bind mode: loopback | lan | auto | custom | tailnet").option("--port <number>", "Port to listen on (defaults to gateway.port in config, else 18790)").option("--token <token>", "Authentication token").option("--tailscale <mode>", "Tailscale exposure: off | serve | funnel (overrides config for this run)").option("--tailscale-reset-on-exit", "Reset Tailscale serve/funnel on gateway shutdown", false).option("--force", "Force kill existing process on port", false).option("--no-hot-reload", "Disable config hot reload").option("--foreground", "Start gateway in foreground mode (blocks terminal)", true);
}
async function tryRunGatewayRunFastPath(argv = process.argv) {
	if (!isGatewayRunFastPathArgv(argv)) return false;
	const { Command } = await import("commander");
	const { runGatewayFromCliOptions } = await import("./commands/gateway/run-foreground.js");
	const program = new Command().name("xopc").description(ROOT_COMMAND_DESCRIPTION).version(version).option("--verbose", "Enable verbose logging", false).option("--config <path>", "Config file path").option("--workspace <path>", "Workspace directory");
	program.hook("preAction", (thisCommand) => {
		parsedOpts = thisCommand.opts();
	});
	const gateway = buildGatewayRunOptions(new Command("gateway"));
	gateway.action(async (options) => {
		await runGatewayFromCliOptions(options, getContextWithOpts(argv));
	});
	program.addCommand(gateway);
	await program.parseAsync(argv);
	const { flushAndClose } = await import("../utils/logger/shutdown.js");
	await flushAndClose();
	return true;
}
//#endregion
export { tryRunGatewayRunFastPath };

//# sourceMappingURL=gateway-run-fast-path.js.map