Skip to content

Commit 2f4d192

Browse files
committed
feat: added rm command
1 parent 80a4668 commit 2f4d192

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nerdctl",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Node wrapper for nerdctl",

src/tests/container.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { factory } from "..";
2+
3+
describe("container", () => {
4+
const engine = factory();
5+
const IMAGE = "hello-world";
6+
const NAME = "hello";
7+
8+
test("rm", async () => {
9+
await engine.run(IMAGE, { name: NAME, detach: true });
10+
const result = await engine.rm(NAME, { force: true });
11+
12+
expect(result.code).toEqual(0);
13+
});
14+
});

src/types/container.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ export interface LogsCommandFlags extends GlobalFlags {
6565
until?: string;
6666
}
6767

68-
export interface ContainerCommandFlags extends GlobalFlags {}
68+
export interface RmCommandFlags extends GlobalFlags {
69+
force?: boolean;
70+
volumes?: boolean;
71+
}

src/vms/base.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Architecture, ExecResult } from "@/types";
2-
import { ContainerCommandFlags, RunCommandFlags } from "@/types/container";
3-
import { ExecOptions, exec } from "shelljs";
2+
import { ExecOptions, ShellString, exec } from "shelljs";
3+
import { RmCommandFlags, RunCommandFlags } from "@/types/container";
44

55
import { ChildProcess } from "child_process";
66
import { GlobalFlags } from "@/types/global";
@@ -76,10 +76,7 @@ export default abstract class BaseBackend {
7676
flags?: RunCommandFlags
7777
): Promise<ExecResult | string>;
7878

79-
abstract rm(
80-
container: string,
81-
flags?: ContainerCommandFlags
82-
): Promise<ChildProcess>;
79+
abstract rm(container: string, flags?: RmCommandFlags): Promise<ShellString>;
8380

8481
abstract pullImage(image: string): Promise<ChildProcess>;
8582
abstract getImages(): Promise<ImageResult[]>;

src/vms/lima.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
ContainerCommandFlags,
32
LogsCommandFlags,
3+
RmCommandFlags,
44
RunCommandFlags,
55
} from "@/types/container";
66

@@ -9,6 +9,7 @@ import { ChildProcess } from "child_process";
99
import { ExecResult } from "@/types";
1010
import { ImageResult } from "@/types/images";
1111
import { LoginCommandFlags } from "@/types/registry";
12+
import { ShellString } from "shelljs";
1213

1314
export default class LimaBackend extends BaseBackend {
1415
async init(): Promise<void> {}
@@ -46,14 +47,11 @@ export default class LimaBackend extends BaseBackend {
4647
});
4748
}
4849

49-
async rm(
50-
container: string,
51-
flags?: ContainerCommandFlags
52-
): Promise<ChildProcess> {
50+
async rm(container: string, flags?: RmCommandFlags): Promise<ShellString> {
5351
return (await this.exec(
5452
`${this.container} rm ${this.mergeFlags(flags)} ${container}`,
5553
{ async: false }
56-
)) as ChildProcess;
54+
)) as ShellString;
5755
}
5856

5957
async logs(

0 commit comments

Comments
 (0)