diff --git a/src/command.ts b/src/command.ts index 5160f30..7ac17d1 100644 --- a/src/command.ts +++ b/src/command.ts @@ -1075,7 +1075,7 @@ function validateCommandName(command: string) { const SHELL_SIGNAL_CTOR_SYMBOL = Symbol(); interface KillSignalState { - abortedCode: number; + abortedCode: number | undefined; listeners: ((signal: Deno.Signal) => void)[]; } @@ -1086,7 +1086,7 @@ export class KillSignalController { constructor() { this.#state = { - abortedCode: 0, + abortedCode: undefined, listeners: [], }; this.#killSignal = new KillSignal(SHELL_SIGNAL_CTOR_SYMBOL, this.#state); @@ -1131,7 +1131,12 @@ export class KillSignal { * SIGKILL, SIGABRT, SIGQUIT, SIGINT, or SIGSTOP */ get aborted(): boolean { - return this.#state.abortedCode !== 0; + return this.#state.abortedCode !== undefined; + } + + /** Gets the exit code to use if aborted. */ + get abortedExitCode(): number | undefined { + return this.#state.abortedCode; } /** @@ -1160,11 +1165,6 @@ export class KillSignal { this.#state.listeners.splice(index, 1); } } - - /** @internal - DO NOT USE. Very unstable. Not sure about this. */ - get _abortedExitCode() { - return this.#state.abortedCode; - } } function sendSignalToState(state: KillSignalState, signal: Deno.Signal) { diff --git a/src/commands/cat.ts b/src/commands/cat.ts index 93392e4..51239dc 100644 --- a/src/commands/cat.ts +++ b/src/commands/cat.ts @@ -32,7 +32,7 @@ async function executeCat(context: CommandContext) { if (!size || size === 0) break; else context.stdout.writeSync(buf.slice(0, size)); } - exitCode = context.signal._abortedExitCode; + exitCode = context.signal.abortedExitCode ?? 0; } else { const _assertValue: "null" | "inherit" = context.stdin; throw new Error(`not supported. stdin was '${context.stdin}'`); @@ -47,7 +47,7 @@ async function executeCat(context: CommandContext) { if (!size || size === 0) break; else context.stdout.writeSync(buf.slice(0, size)); } - exitCode = context.signal._abortedExitCode; + exitCode = context.signal.abortedExitCode ?? 0; } catch (err) { context.stderr.writeLine(`cat ${path}: ${err}`); exitCode = 1;