fix: Fixes patch commander to work properly.

This patch makes the patch code also patch nested createCommand calls.

Yo dawg I heard you like patching.
This commit is contained in:
greysoh 2024-05-06 21:29:00 -04:00
parent ea9279b16d
commit ebda78fd30
No known key found for this signature in database
GPG key ID: FE0F173B8FC01571

View file

@ -1,6 +1,6 @@
// @ts-nocheck
import type { Command } from "commander";
import { Command } from "commander";
import { PrintLine } from "../commands";
export type AppState = {
@ -8,17 +8,24 @@ export type AppState = {
}
export function patchCommander(program: Command, appState: AppState, println: PrintLine) {
program.exitOverride(() => {
appState.hasRecievedExitSignal = true;
});
program._outputConfiguration.writeOut = (str) => println(str);
program._outputConfiguration.writeErr = (str) => {
if (str.includes("--help")) return;
println(str);
};
program._exit = (exitCode, code, message) => {
program._exit = () => {
appState.hasRecievedExitSignal = true;
}
};
program.createCommand = (name: string) => {
const command = new Command(name);
patchCommander(command, appState, println);
return command;
};
program._exitCallback = () => {
appState.hasRecievedExitSignal = true;
};
}