-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprune.js
More file actions
28 lines (24 loc) · 872 Bytes
/
prune.js
File metadata and controls
28 lines (24 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env node
"use strict";
const { readInput, writeResponse, error, stripKeyword } = require("@yoki/plugin-sdk");
const { docker } = require("./lib/docker_cli");
async function main() {
const input = await readInput();
const arg = stripKeyword((input.query || "").trim(), input.command).trim().toLowerCase();
if (arg !== "yes") {
writeResponse({
type: "background",
hud: "Type `dc prune yes` to confirm — removes stopped containers, unused networks, dangling images",
});
return;
}
try {
const out = docker(`system prune -f`);
const match = out.match(/Total reclaimed space:\s*(.+)/i);
const reclaimed = match ? match[1].trim() : "0 B";
writeResponse({ type: "background", hud: `Prune complete — reclaimed ${reclaimed}` });
} catch (e) {
writeResponse(error("prune failed", e.message));
}
}
main();