/**
 * Dotenv resolution helpers shared between the CLI bootstrap
 * (`packages/eval/src/cli.ts`) and any code path that needs to honor the
 * same `--dotenv <path>` override (today: `pipeline/checks.ts::checkEnvironment`,
 * which re-loads the active env file as part of validation).
 *
 * Centralizing the argv parse means future changes — validating the path
 * exists before returning, supporting `--dotenv=path` form, accepting an
 * env-var fallback — happen in one place instead of drifting between
 * call sites.
 */
import { resolve } from "node:path";
/**
 * Find an explicit `--dotenv <path>` argument and return its absolute,
 * resolved path. Returns `undefined` when the flag is absent or has no
 * following value.
 *
 * @param argv - Defaults to `process.argv`. Pass an explicit array in
 *   tests or in non-CLI hosts that have already shifted off the script
 *   prefix.
 */
export function findExplicitDotenvArg(argv = process.argv) {
    const idx = argv.indexOf("--dotenv");
    if (idx === -1)
        return undefined;
    const value = argv[idx + 1];
    if (!value)
        return undefined;
    return resolve(value);
}
