//#region src/cli/argv.ts
const ROOT_VALUE_FLAGS = new Set(["--config", "--workspace"]);
function isHelpOrVersionInvocation(argv) {
	return argv.some((arg) => arg === "--help" || arg === "-h" || arg === "--version" || arg === "-V");
}
function isRootHelpInvocation(argv) {
	const args = argv.slice(2).filter((arg) => arg !== "--");
	if (args.length === 0) return false;
	if (args.length === 1 && (args[0] === "--help" || args[0] === "-h" || args[0] === "help")) return true;
	return false;
}
function getPrimaryCommand(argv) {
	return resolveCliCommandPath(argv)[0] ?? null;
}
/**
* Walk argv and collect command tokens (skips global flags and `help` prefix).
*/
function resolveCliCommandPath(argv) {
	const path = [];
	let index = 2;
	while (index < argv.length) {
		const arg = argv[index];
		if (!arg) {
			index += 1;
			continue;
		}
		if (arg === "--") break;
		if (arg.startsWith("-")) {
			index += ROOT_VALUE_FLAGS.has(arg) ? 2 : 1;
			continue;
		}
		if (path.length === 0 && arg === "help") {
			index += 1;
			continue;
		}
		path.push(arg);
		index += 1;
	}
	return path;
}
//#endregion
export { getPrimaryCommand, isHelpOrVersionInvocation, isRootHelpInvocation, resolveCliCommandPath };

//# sourceMappingURL=argv.js.map