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:
parent
ea9279b16d
commit
ebda78fd30
1 changed files with 14 additions and 7 deletions
|
@ -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;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue