@kill-switch/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.d.ts +15 -0
- package/dist/api-client.js +46 -0
- package/dist/commands/accounts.d.ts +2 -0
- package/dist/commands/accounts.js +133 -0
- package/dist/commands/alerts.d.ts +2 -0
- package/dist/commands/alerts.js +49 -0
- package/dist/commands/analytics.d.ts +2 -0
- package/dist/commands/analytics.js +35 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +85 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +37 -0
- package/dist/commands/config-cmd.d.ts +2 -0
- package/dist/commands/config-cmd.js +72 -0
- package/dist/commands/kill.d.ts +2 -0
- package/dist/commands/kill.js +125 -0
- package/dist/commands/onboard.d.ts +24 -0
- package/dist/commands/onboard.js +340 -0
- package/dist/commands/rules.d.ts +2 -0
- package/dist/commands/rules.js +121 -0
- package/dist/commands/shield.d.ts +2 -0
- package/dist/commands/shield.js +57 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.js +49 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +42 -0
- package/dist/output.d.ts +18 -0
- package/dist/output.js +60 -0
- package/package.json +28 -0
package/dist/output.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting — tables for humans, JSON for machines
|
|
3
|
+
*/
|
|
4
|
+
export function formatTable(rows, columns) {
|
|
5
|
+
if (rows.length === 0) {
|
|
6
|
+
console.log("No results.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
// Calculate column widths
|
|
10
|
+
const widths = columns.map((col) => {
|
|
11
|
+
const headerLen = col.header.length;
|
|
12
|
+
const maxData = rows.reduce((max, row) => {
|
|
13
|
+
const val = String(row[col.key] ?? "");
|
|
14
|
+
return Math.max(max, val.length);
|
|
15
|
+
}, 0);
|
|
16
|
+
return col.width || Math.min(Math.max(headerLen, maxData) + 2, 40);
|
|
17
|
+
});
|
|
18
|
+
// Header
|
|
19
|
+
const headerLine = columns
|
|
20
|
+
.map((col, i) => col.header.padEnd(widths[i]))
|
|
21
|
+
.join(" ");
|
|
22
|
+
console.log(headerLine);
|
|
23
|
+
console.log(widths.map((w) => "-".repeat(w)).join(" "));
|
|
24
|
+
// Rows
|
|
25
|
+
for (const row of rows) {
|
|
26
|
+
const line = columns
|
|
27
|
+
.map((col, i) => String(row[col.key] ?? "").padEnd(widths[i]).slice(0, widths[i]))
|
|
28
|
+
.join(" ");
|
|
29
|
+
console.log(line);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function formatObject(obj, fields) {
|
|
33
|
+
const keys = fields || Object.keys(obj);
|
|
34
|
+
const maxKeyLen = keys.reduce((max, k) => Math.max(max, k.length), 0);
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
const val = obj[key];
|
|
37
|
+
const display = typeof val === "object" ? JSON.stringify(val) : String(val ?? "");
|
|
38
|
+
console.log(`${key.padEnd(maxKeyLen + 2)}${display}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function outputJson(data) {
|
|
42
|
+
console.log(JSON.stringify(data, null, 2));
|
|
43
|
+
}
|
|
44
|
+
export function outputError(message, json) {
|
|
45
|
+
if (json) {
|
|
46
|
+
console.error(JSON.stringify({ error: message }));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.error(`Error: ${message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Wrap a command handler with JSON/error handling.
|
|
54
|
+
*/
|
|
55
|
+
export function withOutput(fn, opts) {
|
|
56
|
+
return fn(opts).catch((err) => {
|
|
57
|
+
outputError(err.message || String(err), opts.json);
|
|
58
|
+
process.exit(err.status === 401 || err.status === 403 ? 2 : 1);
|
|
59
|
+
});
|
|
60
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kill-switch/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Kill Switch CLI — monitor cloud spending, kill runaway services from the terminal",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"kill-switch": "./dist/index.js",
|
|
8
|
+
"ks": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsx src/index.ts",
|
|
13
|
+
"test": "vitest run"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"commander": "^12.1.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^5.4.0",
|
|
20
|
+
"tsx": "^4.7.0",
|
|
21
|
+
"@types/node": "^22.0.0"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist"],
|
|
27
|
+
"license": "MIT"
|
|
28
|
+
}
|