@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/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
+ }