Skip to content

Commit 3f54ea1

Browse files
feat: force collie to exit when receiving second interrupt from user
this is consistent with the behavior of terraform/terragrunt
1 parent e15aad1 commit 3f54ea1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { makeTopLevelCommand } from "./commands/TopLevelCommand.ts";
1919
import { registerInfoCommand } from "./commands/info.command.ts";
2020
import { registerConfigCommand } from "./commands/config/config.command.ts";
2121

22+
let shutdownRequested = 0;
23+
2224
async function collie() {
2325
const program = makeTopLevelCommand()
2426
.name(CLI)
@@ -99,9 +101,22 @@ if (import.meta.main) {
99101
}
100102

101103
function gracefulShutdown(): void {
104+
shutdownRequested += 1;
105+
106+
if (shutdownRequested == 1) {
107+
logWithBanner(
108+
"Interrupt received.\nPlease wait for collie shut down or data loss may occur.\nGracefully shutting down...",
109+
);
110+
} else {
111+
logWithBanner(
112+
"Two interrupts received, collie will now exit. Data loss may occur.",
113+
);
114+
Deno.exit(143);
115+
}
116+
}
117+
118+
function logWithBanner(msg: string) {
102119
console.log("\n\n");
103-
console.log(
104-
"Interrupt received.\nPlease wait for collie shut down or data loss may occur.\nGracefully shutting down...",
105-
);
120+
console.log(msg);
106121
console.log("\n\n");
107122
}

0 commit comments

Comments
 (0)