import { y as parseStrictPositiveInteger } from "./number-coercion-CU7MBp2A.js";
import "./parse-finite-number-D0XNMNbx.js";
import { InvalidArgumentError } from "commander";
//#region src/cli/program/helpers.ts
function collectOption(value, previous = []) {
	return [...previous, value];
}
function parsePositiveIntOrUndefined(value) {
	if (value === void 0 || value === null || value === "") return;
	return parseStrictPositiveInteger(value);
}
function parseStrictPositiveIntOrUndefined(value) {
	return parseStrictPositiveInteger(value);
}
function parseStrictPositiveIntOption(value, flag) {
	const parsed = parseStrictPositiveInteger(value);
	if (parsed === void 0) throw new InvalidArgumentError(`${flag} must be a positive integer.`);
	return parsed;
}
function resolveActionArgs(actionCommand) {
	if (!actionCommand) return [];
	const args = actionCommand.args;
	return Array.isArray(args) ? args : [];
}
function isDefaultOptionValue(command, name) {
	if (typeof command.getOptionValueSource !== "function") return false;
	return command.getOptionValueSource(name) === "default";
}
function appendOptionValue(out, flag, value) {
	if (value === void 0) return;
	if (value === false) {
		if (flag.startsWith("--no-")) out.push(flag);
		return;
	}
	if (value === true) {
		out.push(flag);
		return;
	}
	const arg = stringifyOptionValue(value);
	if (arg !== void 0) out.push(flag, arg);
}
function stringifyOptionValue(value) {
	if (typeof value === "string") return value;
	if (typeof value === "number" && Number.isFinite(value)) return String(value);
	if (typeof value === "bigint") return value.toString();
}
function resolveCommandOptionArgs(command) {
	if (!command) return [];
	const out = [];
	for (const option of command.options) {
		const name = option.attributeName();
		if (isDefaultOptionValue(command, name)) continue;
		const flag = option.long ?? option.short;
		if (!flag) continue;
		const value = command.getOptionValue(name);
		if (Array.isArray(value)) {
			for (const item of value) appendOptionValue(out, flag, item);
			continue;
		}
		appendOptionValue(out, flag, value);
	}
	return out;
}
//#endregion
export { resolveActionArgs as a, parseStrictPositiveIntOrUndefined as i, parsePositiveIntOrUndefined as n, resolveCommandOptionArgs as o, parseStrictPositiveIntOption as r, collectOption as t };
