@moor-sh/cli 0.4.0 → 0.5.1
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/bin/moor.js +2 -0
- package/dist/index.js +701 -0
- package/package.json +7 -4
- package/src/client.ts +0 -106
- package/src/commands/env.ts +0 -97
- package/src/commands/exec.ts +0 -29
- package/src/commands/history.test.ts +0 -37
- package/src/commands/history.ts +0 -117
- package/src/commands/logs.ts +0 -62
- package/src/commands/mcp.ts +0 -136
- package/src/commands/rebuild.ts +0 -40
- package/src/commands/restart.ts +0 -27
- package/src/commands/stats.ts +0 -34
- package/src/commands/status.ts +0 -56
- package/src/index.ts +0 -90
package/src/commands/stats.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { apiGet } from "../client";
|
|
2
|
-
|
|
3
|
-
type ServerStats = {
|
|
4
|
-
hostname: string;
|
|
5
|
-
os: string;
|
|
6
|
-
uptime: string;
|
|
7
|
-
cpu: { percent: number; cores: number };
|
|
8
|
-
memory: { total: string; used: string; percent: number };
|
|
9
|
-
disk: { total: string; used: string; percent: number };
|
|
10
|
-
disks?: { mount: string; total: string; used: string; percent: number }[];
|
|
11
|
-
containers: { running: number; total: number };
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export async function statsCommand() {
|
|
15
|
-
const res = await apiGet("/api/server/stats");
|
|
16
|
-
if (!res.ok) {
|
|
17
|
-
console.error(`Failed to get stats: ${res.status}`);
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const s = (await res.json()) as ServerStats;
|
|
22
|
-
|
|
23
|
-
console.log(`Host: ${s.hostname}`);
|
|
24
|
-
console.log(`OS: ${s.os}`);
|
|
25
|
-
console.log(`Uptime: ${s.uptime}`);
|
|
26
|
-
console.log(`CPU: ${s.cpu.percent}% (${s.cpu.cores} cores)`);
|
|
27
|
-
console.log(`Memory: ${s.memory.used} / ${s.memory.total} (${s.memory.percent}%)`);
|
|
28
|
-
const disks = s.disks?.length ? s.disks : [{ mount: "/", ...s.disk }];
|
|
29
|
-
disks.forEach((d, i) => {
|
|
30
|
-
const label = i === 0 ? "Disk:" : " ";
|
|
31
|
-
console.log(`${label} ${d.mount} ${d.used} / ${d.total} (${d.percent}%)`);
|
|
32
|
-
});
|
|
33
|
-
console.log(`Containers: ${s.containers.running} running / ${s.containers.total} total`);
|
|
34
|
-
}
|
package/src/commands/status.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { apiGet } from "../client";
|
|
2
|
-
|
|
3
|
-
type Project = {
|
|
4
|
-
id: number;
|
|
5
|
-
name: string;
|
|
6
|
-
status: string;
|
|
7
|
-
image_tag: string | null;
|
|
8
|
-
domain: string | null;
|
|
9
|
-
docker_image: string | null;
|
|
10
|
-
github_url: string | null;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export async function statusCommand() {
|
|
14
|
-
const res = await apiGet("/api/projects");
|
|
15
|
-
if (!res.ok) {
|
|
16
|
-
console.error(`Failed to list projects: ${res.status}`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const projects = (await res.json()) as Project[];
|
|
21
|
-
if (projects.length === 0) {
|
|
22
|
-
console.log("No projects found.");
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Calculate column widths
|
|
27
|
-
const nameW = Math.max(4, ...projects.map((p) => p.name.length));
|
|
28
|
-
const statusW = Math.max(6, ...projects.map((p) => p.status.length));
|
|
29
|
-
const sourceW = Math.max(
|
|
30
|
-
6,
|
|
31
|
-
...projects.map((p) => (p.docker_image || p.github_url || "-").length),
|
|
32
|
-
);
|
|
33
|
-
const domainW = Math.max(6, ...projects.map((p) => (p.domain || "-").length));
|
|
34
|
-
|
|
35
|
-
const header = [
|
|
36
|
-
"NAME".padEnd(nameW),
|
|
37
|
-
"STATUS".padEnd(statusW),
|
|
38
|
-
"SOURCE".padEnd(sourceW),
|
|
39
|
-
"DOMAIN".padEnd(domainW),
|
|
40
|
-
].join(" ");
|
|
41
|
-
|
|
42
|
-
console.log(header);
|
|
43
|
-
console.log("-".repeat(header.length));
|
|
44
|
-
|
|
45
|
-
for (const p of projects) {
|
|
46
|
-
const source = p.docker_image || p.github_url || "-";
|
|
47
|
-
console.log(
|
|
48
|
-
[
|
|
49
|
-
p.name.padEnd(nameW),
|
|
50
|
-
p.status.padEnd(statusW),
|
|
51
|
-
source.padEnd(sourceW),
|
|
52
|
-
(p.domain || "-").padEnd(domainW),
|
|
53
|
-
].join(" "),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { envCommand } from "./commands/env";
|
|
5
|
-
import { execCommand } from "./commands/exec";
|
|
6
|
-
import { historyCommand } from "./commands/history";
|
|
7
|
-
import { logsCommand } from "./commands/logs";
|
|
8
|
-
import { mcpCommand } from "./commands/mcp";
|
|
9
|
-
import { rebuildCommand } from "./commands/rebuild";
|
|
10
|
-
import { restartCommand } from "./commands/restart";
|
|
11
|
-
import { statsCommand } from "./commands/stats";
|
|
12
|
-
import { statusCommand } from "./commands/status";
|
|
13
|
-
|
|
14
|
-
// Read version from package.json at runtime so the binary always reports the
|
|
15
|
-
// real shipped version. import.meta.dir resolves to packages/cli/src in this
|
|
16
|
-
// repo and to <install-root>/src in a published install; ../package.json is
|
|
17
|
-
// the package root in both cases.
|
|
18
|
-
const VERSION = (
|
|
19
|
-
JSON.parse(readFileSync(join(import.meta.dir, "..", "package.json"), "utf8")) as {
|
|
20
|
-
version: string;
|
|
21
|
-
}
|
|
22
|
-
).version;
|
|
23
|
-
|
|
24
|
-
function printHelp() {
|
|
25
|
-
console.log(`moor - CLI for Moor server management
|
|
26
|
-
|
|
27
|
-
Usage: moor <command> [options]
|
|
28
|
-
|
|
29
|
-
Commands:
|
|
30
|
-
status List all projects
|
|
31
|
-
logs <project> [-f] [-n <lines>] View container logs
|
|
32
|
-
rebuild <project> [--no-cache] Rebuild and restart from source
|
|
33
|
-
restart <project> Stop and start a container
|
|
34
|
-
exec <project> <command> Run a command in a container
|
|
35
|
-
env list <project> List environment variables
|
|
36
|
-
env set <project> K=V [K=V ...] Set environment variables
|
|
37
|
-
stats Show server resource usage
|
|
38
|
-
history <project> [--hours N] Stored resource history + events (default 24h)
|
|
39
|
-
mcp config --client <name> Generate MCP client config snippet
|
|
40
|
-
|
|
41
|
-
Environment:
|
|
42
|
-
MOOR_URL Server URL (e.g. https://moor.example.com)
|
|
43
|
-
MOOR_API_KEY API key for authentication`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const args = process.argv.slice(2);
|
|
47
|
-
const command = args[0];
|
|
48
|
-
|
|
49
|
-
switch (command) {
|
|
50
|
-
case "status":
|
|
51
|
-
await statusCommand();
|
|
52
|
-
break;
|
|
53
|
-
case "logs":
|
|
54
|
-
await logsCommand(args.slice(1));
|
|
55
|
-
break;
|
|
56
|
-
case "rebuild":
|
|
57
|
-
await rebuildCommand(args.slice(1));
|
|
58
|
-
break;
|
|
59
|
-
case "restart":
|
|
60
|
-
await restartCommand(args.slice(1));
|
|
61
|
-
break;
|
|
62
|
-
case "exec":
|
|
63
|
-
await execCommand(args.slice(1));
|
|
64
|
-
break;
|
|
65
|
-
case "env":
|
|
66
|
-
await envCommand(args.slice(1));
|
|
67
|
-
break;
|
|
68
|
-
case "stats":
|
|
69
|
-
await statsCommand();
|
|
70
|
-
break;
|
|
71
|
-
case "history":
|
|
72
|
-
await historyCommand(args.slice(1));
|
|
73
|
-
break;
|
|
74
|
-
case "mcp":
|
|
75
|
-
mcpCommand(args.slice(1));
|
|
76
|
-
break;
|
|
77
|
-
case "--help":
|
|
78
|
-
case "-h":
|
|
79
|
-
case "help":
|
|
80
|
-
printHelp();
|
|
81
|
-
break;
|
|
82
|
-
case "--version":
|
|
83
|
-
case "-v":
|
|
84
|
-
console.log(VERSION);
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
if (command) console.error(`Unknown command: ${command}\n`);
|
|
88
|
-
printHelp();
|
|
89
|
-
process.exit(command ? 1 : 0);
|
|
90
|
-
}
|