-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker.ts
58 lines (54 loc) · 2.18 KB
/
docker.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { evaluateSystemCommand, spawn } from "../src/helpers.ts";
import Plugin from "../src/plugin.ts";
class Docker implements Plugin {
name = "docker";
commands: Record<string, (params: string[]) => Promise<void>>;
constructor() {
this.commands = {
run: (args: string[]) => spawn(this.name, ["run", ...args]),
ps: (args: string[]) => spawn(this.name, ["ps", ...args]),
container: (args: string[]) => spawn(this.name, ["container", ...args]),
images: (args: string[]) => spawn(this.name, ["images", ...args]),
exec: (args: string[]) => spawn(this.name, ["exec", ...args]),
build: (args: string[]) => spawn(this.name, ["build", ...args]),
pull: (args: string[]) => spawn(this.name, ["pull", ...args]),
push: (args: string[]) => spawn(this.name, ["push", ...args]),
search: (args: string[]) => spawn(this.name, ["search", ...args]),
version: (args: string[]) => spawn(this.name, ["version", ...args]),
info: (args: string[]) => spawn(this.name, ["info", ...args]),
compose: (args: string[]) => spawn(this.name, ["compose", ...args]),
help: () => {
console.log(` Common Commands:
run Create and run a new container from an image
exec Execute a command in a running container
ps List containers
build Build an image from a Dockerfile
pull Download an image from a registry
push Upload an image to a registry
images List images
login Log in to a registry
logout Log out from a registry
search Search Docker Hub for images
version Show the Docker version information
info Display system-wide information
compose Docker Compose`);
return Promise.resolve();
},
};
}
async evaluate(command: string): Promise<void> {
const [cmd, ...params] = command.split(" ");
if (this.commands[cmd]) {
await this.commands[cmd](params);
return;
}
if (cmd === "") {
return;
}
await evaluateSystemCommand(command);
}
async install(): Promise<void> {
// TODO: install docker
}
}
export default Docker;