/** Tokens before a bare `--`; everything after it is positional data, * never a flag. */ export function flagTokens(argv: readonly string[]): readonly string[] { const end = argv.indexOf("--"); return end === -1 ? argv : argv.slice(0, end); } /** The file an explicit --config names. Discovery otherwise anchors at * cwd. */ export function configPathFromArgv( argv: readonly string[], ): string | undefined { const tokens = flagTokens(argv); for (let index = 0; index < tokens.length; index += 1) { const token = tokens[index] as string; if (token === "--config") { return tokens[index + 1]; } if (token.startsWith("--config=")) { return token.slice("--config=".length); } } return undefined; }