import { resolveCliArgvInvocation } from "../../argv-invocation.js";
import { isKnownGatewaySubcommand, resolveGatewaySubcommandName } from "../../gateway-run-argv.js";
//#region src/cli/commands/gateway/subcommands.ts
const GATEWAY_SUBCOMMAND_LOADERS = {
	token: async () => (await import("./token.js")).createTokenCommand(),
	status: async () => (await import("./status.js")).createStatusCommand(),
	health: async () => (await import("./health.js")).createHealthCommand(),
	call: async () => (await import("./call.js")).createCallCommand(),
	probe: async () => (await import("./probe.js")).createProbeCommand(),
	stop: async () => (await import("./stop.js")).createStopCommand(),
	restart: async () => (await import("./restart.js")).createRestartCommand(),
	logs: async () => (await import("./logs.js")).createLogsCommand(),
	service: async () => (await import("./service.js")).createServiceCommand()
};
async function attachAllGatewaySubcommands(cmd, ctx) {
	for (const loader of Object.values(GATEWAY_SUBCOMMAND_LOADERS)) cmd.addCommand(await loader());
	const { registerGatewaySshTunnelCommand } = await import("../gateway-ssh-tunnel.js");
	registerGatewaySshTunnelCommand(cmd, ctx);
}
function shouldEagerLoadGatewaySubcommands(argv) {
	if (!resolveCliArgvInvocation(argv).hasHelpOrVersion) return false;
	return resolveGatewaySubcommandName(argv) === void 0;
}
async function prepareGatewayCommandForArgv(cmd, ctx) {
	const subcommand = resolveGatewaySubcommandName(ctx.argv);
	if (subcommand === "ssh-tunnel") {
		const { registerGatewaySshTunnelCommand } = await import("../gateway-ssh-tunnel.js");
		registerGatewaySshTunnelCommand(cmd, ctx);
		return;
	}
	if (subcommand && isKnownGatewaySubcommand(subcommand)) {
		const loader = GATEWAY_SUBCOMMAND_LOADERS[subcommand];
		if (loader) cmd.addCommand(await loader());
		return;
	}
	if (shouldEagerLoadGatewaySubcommands(ctx.argv)) await attachAllGatewaySubcommands(cmd, ctx);
}
//#endregion
export { prepareGatewayCommandForArgv };

//# sourceMappingURL=subcommands.js.map