/**
 * args.mjs — flag parsing extracted from apt-tools.mjs (C29).
 */

/**
 * Parse flags from an args array. Supports both `--flag value` pairs and
 * bare boolean `--flag` forms (value becomes `true` when the flag has no
 * following non-flag argument).
 * Returns a Map of flag name (without --) to string | true.
 */
export function parseFlags(args) {
	const flags = new Map()
	for (let i = 0; i < args.length; i++) {
		const arg = args[i]
		if (!arg.startsWith('--')) continue
		const key = arg.slice(2)
		const next = args[i + 1]
		if (next !== undefined && !next.startsWith('--')) {
			flags.set(key, next)
			i++ // skip value
		} else {
			flags.set(key, true)
		}
	}
	return flags
}
