fix: --help and --version redirect

This commit is contained in:
Armin Ronacher
2026-06-09 13:43:54 +02:00
parent 359a0769f1
commit c20ea06d4a
2 changed files with 26 additions and 5 deletions

View File

@@ -112,6 +112,10 @@ function toPrintOutputMode(appMode: AppMode): Exclude<Mode, "rpc"> {
return appMode === "json" ? "json" : "text";
}
function isPlainRuntimeMetadataCommand(parsed: Args): boolean {
return !parsed.print && parsed.mode === undefined && (parsed.help === true || parsed.listModels !== undefined);
}
async function prepareInitialMessage(
parsed: Args,
autoResizeImages: boolean,
@@ -480,11 +484,6 @@ export async function main(args: string[], options?: MainOptions) {
}
}
time("parseArgs");
let appMode = resolveAppMode(parsed, process.stdin.isTTY, process.stdout.isTTY);
const shouldTakeOverStdout = appMode !== "interactive";
if (shouldTakeOverStdout) {
takeOverStdout();
}
if (parsed.version) {
console.log(VERSION);
@@ -505,6 +504,12 @@ export async function main(args: string[], options?: MainOptions) {
process.exit(0);
}
let appMode = resolveAppMode(parsed, process.stdin.isTTY, process.stdout.isTTY);
const shouldTakeOverStdout = appMode !== "interactive" && !isPlainRuntimeMetadataCommand(parsed);
if (shouldTakeOverStdout) {
takeOverStdout();
}
if (parsed.mode === "rpc" && parsed.fileArgs.length > 0) {
console.error(chalk.red("Error: @file arguments are not supported in RPC mode"));
process.exit(1);