"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_primordials_string = require('../primordials/string.js');
const require_primordials_array = require('../primordials/array.js');
const require_primordials_object = require('../primordials/object.js');
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process);
let src_external_yargs_parser = require("../external/yargs-parser");
src_external_yargs_parser = require_runtime.__toESM(src_external_yargs_parser);

//#region src/argv/parse.ts
/**
* @file Argument parsing utilities for CLI applications. Wraps the vendored
*   yargs-parser with a Node.js parseArgs-compatible surface for booleans,
*   strings, arrays, aliases, defaults, and coercion.
*/
/**
* Common parseArgs configuration for Socket registry scripts.
*/
const commonParseArgsConfig = {
	options: {
		force: {
			type: "boolean",
			short: "f",
			default: false
		},
		quiet: {
			type: "boolean",
			short: "q",
			default: false
		}
	},
	strict: false
};
/**
* Extract positional arguments from process.argv. Useful for commands that
* accept file paths or other positional parameters.
*
* @example
*   ;```typescript
*   // process.argv = ["node", "script.js", "src", "lib", "--verbose"]
*   getPositionalArgs() // ["src", "lib"]
*   ```
*/
function getPositionalArgs(startIndex = 2) {
	const args = node_process.default.argv.slice(startIndex);
	const positionals = [];
	let i = 0;
	while (i < args.length) {
		const arg = args[i];
		if (require_primordials_string.StringPrototypeStartsWith(arg, "-")) break;
		positionals.push(arg);
		i++;
	}
	return positionals;
}
/**
* Check if a specific flag is present in argv.
*
* @example
*   ;```typescript
*   hasFlag('verbose') // true if --verbose is in process.argv
*   hasFlag('force', ['--force', '--quiet']) // true
*   ```
*/
function hasFlag(flag, argv = node_process.default.argv) {
	return require_primordials_array.ArrayPrototypeIncludes(argv, `--${flag}`);
}
/**
* Parse command-line arguments with a Node.js parseArgs-compatible API. Uses
* yargs-parser internally for robust argument parsing.
*
* @example
*   ;```typescript
*   const { values, positionals } = parseArgs({
*     args: ['--force', '--quiet', 'file.ts'],
*     options: {
*       force: { type: 'boolean' },
*       quiet: { type: 'boolean', short: 'q' },
*     },
*   })
*   ```
*/
function parseArgs(config = {}) {
	const { allowNegative = false, allowPositionals = true, args = node_process.default.argv.slice(2), configuration, options = {}, strict = true } = config;
	const yargsOptions = {
		boolean: [],
		string: [],
		array: [],
		alias: {},
		default: {},
		coerce: {},
		"unknown-options-as-args": !strict,
		"parse-numbers": false,
		"parse-positional-numbers": false,
		"boolean-negation": !allowNegative,
		"halt-at-non-option": !allowPositionals,
		configuration: {
			"camel-case-expansion": true,
			"dot-notation": false,
			"duplicate-arguments-array": true,
			"flatten-duplicate-arrays": true,
			"populate--": true,
			"short-option-groups": true,
			"strip-aliased": false,
			"strip-dashed": false,
			...configuration
		}
	};
	for (const { 0: key, 1: optionConfig } of require_primordials_object.ObjectEntries(options)) {
		const { coerce, default: defaultValue, multiple, short, type } = optionConfig;
		if (type === "boolean") yargsOptions.boolean?.push(key);
		else if (type === "string") yargsOptions.string?.push(key);
		if (multiple) yargsOptions.array?.push(key);
		if (short) yargsOptions.alias[short] = key;
		if (defaultValue !== void 0) yargsOptions.default[key] = defaultValue;
		if (coerce) yargsOptions.coerce[key] = coerce;
	}
	const parsed = (0, src_external_yargs_parser.default)(args, yargsOptions);
	const positionals = parsed._ || [];
	const { _, ...values } = parsed;
	return {
		values,
		positionals: positionals.map(String),
		raw: parsed
	};
}
/**
* Parse command-line arguments with Socket defaults. Provides sensible defaults
* for Socket CLI applications.
*
* @example
*   ;```typescript
*   const { values, positionals } = parseArgsWithDefaults({
*     args: ['--force', 'file.ts'],
*     options: { force: { type: 'boolean' } },
*   })
*   ```
*/
function parseArgsWithDefaults(config = {}) {
	return parseArgs({
		strict: false,
		allowPositionals: true,
		...config
	});
}

//#endregion
exports.commonParseArgsConfig = commonParseArgsConfig;
exports.getPositionalArgs = getPositionalArgs;
exports.hasFlag = hasFlag;
exports.parseArgs = parseArgs;
exports.parseArgsWithDefaults = parseArgsWithDefaults;