cassian-cli 0.1.4 → 0.1.5
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/commands/exec.d.ts +1 -0
- package/dist/commands/exec.js +36 -0
- package/dist/commands/up.js +1 -0
- package/dist/index.js +6 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function exec(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/api.js";
|
|
2
|
+
import { loadConfig } from "../lib/config.js";
|
|
3
|
+
import { fatal, handleError } from "../lib/errors.js";
|
|
4
|
+
export async function exec(args) {
|
|
5
|
+
if (args.length === 0) {
|
|
6
|
+
fatal("No command specified.", "Usage: cassian exec <command>");
|
|
7
|
+
}
|
|
8
|
+
const command = args.join(" ");
|
|
9
|
+
let config;
|
|
10
|
+
try {
|
|
11
|
+
config = loadConfig();
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
fatal(e.message);
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const client = new ApiClient();
|
|
18
|
+
const { instances } = await client.get("/v1/instances");
|
|
19
|
+
const instance = instances.find((i) => i.name === config.name && i.status === "running");
|
|
20
|
+
if (!instance) {
|
|
21
|
+
fatal(`${config.name} is not running.`, "Run: cassian up");
|
|
22
|
+
}
|
|
23
|
+
const result = await client.post(`/v1/instances/${instance.id}/exec`, {
|
|
24
|
+
command,
|
|
25
|
+
timeout: 60,
|
|
26
|
+
});
|
|
27
|
+
if (result.stdout)
|
|
28
|
+
process.stdout.write(result.stdout);
|
|
29
|
+
if (result.stderr)
|
|
30
|
+
process.stderr.write(result.stderr);
|
|
31
|
+
process.exit(result.exit_code);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
handleError(err);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/commands/up.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { status } from "./commands/status.js";
|
|
|
14
14
|
import { logs } from "./commands/logs.js";
|
|
15
15
|
import { volumeCreate, volumeList, volumeDelete } from "./commands/volume.js";
|
|
16
16
|
import { sync } from "./commands/sync.js";
|
|
17
|
+
import { exec } from "./commands/exec.js";
|
|
17
18
|
const program = new Command();
|
|
18
19
|
program
|
|
19
20
|
.name("cassian")
|
|
@@ -39,6 +40,11 @@ program
|
|
|
39
40
|
.command("ssh")
|
|
40
41
|
.description("SSH into the running instance")
|
|
41
42
|
.action(ssh);
|
|
43
|
+
program
|
|
44
|
+
.command("exec <command...>")
|
|
45
|
+
.description("Run a command on the instance and return output")
|
|
46
|
+
.option("--timeout <seconds>", "Command timeout in seconds", "60")
|
|
47
|
+
.action((command, opts) => exec(command));
|
|
42
48
|
program
|
|
43
49
|
.command("sync")
|
|
44
50
|
.description("Sync workspace from instance to local")
|
package/dist/types.d.ts
CHANGED