Skip to content

Commit 42f8559

Browse files
authored
Release/v2.1.1 (#19)
* AGENTS.md: Update instructions * postinstall.js: Change DOCKER_FLAGS.txt content * Add ability to pass flags to `container run` * v2.1.1
1 parent 9b52a3e commit 42f8559

7 files changed

Lines changed: 34 additions & 16 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**Important: Role Identification:** Identify whether your user is a **developer** or a **consumer**.
1+
**Important: You must perform user identification.** Identify whether your user is a **developer** or a **consumer**.
22

33
If your user asks questions like:
44
- Help me setup `container` / code-container / this project
@@ -102,6 +102,7 @@ All user data stored in `~/.code-container/`:
102102
## CLI Commands
103103

104104
- `container [path]` — Run container for project (`commands.ts:runContainer`)
105+
- `container run [path] [-- DOCKER_FLAGS]` — Run container with optional Docker flags
105106
- `container build` — Build Docker image (`commands.ts:buildImage`)
106107
- `container init` — Initialize config files (`commands.ts:init`)
107108
- `container stop` — Stop container (`commands.ts:stopContainerForProject`)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-container",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Manage isolated Docker containers for running coding tools on different projects",
55
"main": "dist/main.js",
66
"bin": {

scripts/postinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ if (!fs.existsSync(DOCKERFILE_PATH)) {
2323
}
2424

2525
if (!fs.existsSync(FLAGS_PATH)) {
26-
fs.writeFileSync(FLAGS_PATH, "# Add custom Docker flags here (one per line)\n# Example: -p 7777:7777\n");
26+
fs.writeFileSync(FLAGS_PATH, "# Add custom Docker flags here (one per line)\n# Note: These flags are passed to every created container.\n");
2727
}

src/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function init(isStartup: boolean = false): Promise<void> {
8787
}
8888
}
8989

90-
export async function runContainer(projectPath: string): Promise<void> {
90+
export async function runContainer(projectPath: string, cliFlags: string[] = []): Promise<void> {
9191
const containerName = generateContainerName(projectPath);
9292
const projectName = path.basename(projectPath);
9393

@@ -124,7 +124,7 @@ export async function runContainer(projectPath: string): Promise<void> {
124124
printInfo(`Creating new container: ${containerName}`);
125125
printInfo(`Project: ${projectPath}`);
126126

127-
if (!createNewContainer(containerName, projectName, projectPath)) {
127+
if (!createNewContainer(containerName, projectName, projectPath, cliFlags)) {
128128
printError("Failed to create container");
129129
process.exit(1);
130130
}

src/docker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export function removeContainer(containerName: string): void {
106106
export function createNewContainer(
107107
containerName: string,
108108
projectName: string,
109-
projectPath: string
109+
projectPath: string,
110+
cliFlags: string[] = []
110111
): boolean {
111112
const mounts = getMounts(projectPath, projectName);
112113
const args = ["run", "-d", "--name", containerName];
@@ -120,6 +121,7 @@ export function createNewContainer(
120121

121122
const flags = loadFlags();
122123
args.push(...flags);
124+
args.push(...cliFlags);
123125

124126
args.push(`${IMAGE_NAME}:${IMAGE_TAG}`, "sleep", "infinity");
125127

src/main.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function ensureTosAccepted(): Promise<boolean> {
5757

5858
function usage(): void {
5959
console.log(`
60-
Usage: container [COMMAND] [PROJECT_PATH]
60+
Usage: container [COMMAND] [PROJECT_PATH] [-- DOCKER_FLAGS...]
6161
6262
Manage Code containers for isolated project environments.
6363
@@ -73,10 +73,13 @@ Commands:
7373
7474
Arguments:
7575
PROJECT_PATH Path to the project directory (defaults to current directory)
76+
DOCKER_FLAGS Additional flags passed to 'docker run' after '--'
7677
7778
Examples:
7879
container # Start container for current directory
7980
container run /path/to/project # Start container for specific project
81+
container run /path -- -p 8080:80 # Pass Docker flags for port mapping
82+
container run -- -e FOO=bar # Pass env vars (uses current directory)
8083
container build # Build Docker image
8184
container init # Copy config files
8285
container stop # Stop container for current directory
@@ -91,6 +94,7 @@ async function main(): Promise<void> {
9194
const args = process.argv.slice(2);
9295
let command = "";
9396
let projectPath = "";
97+
let cliFlags: string[] = [];
9498

9599
if (args.length > 0) {
96100
const firstArg = args[0];
@@ -109,12 +113,23 @@ async function main(): Promise<void> {
109113
];
110114
if (validCommands.includes(firstArg)) {
111115
command = firstArg;
112-
if (args.length > 1) {
113-
projectPath = args[1];
114-
}
115-
if (args.length > 2) {
116-
printError(`Unexpected argument: ${args[2]}`);
117-
usage();
116+
const remainingArgs = args.slice(1);
117+
const separatorIndex = remainingArgs.indexOf("--");
118+
119+
if (separatorIndex !== -1) {
120+
const pathArgs = remainingArgs.slice(0, separatorIndex);
121+
if (pathArgs.length > 1) {
122+
printError(`Unexpected argument: ${pathArgs[1]}`);
123+
usage();
124+
}
125+
projectPath = pathArgs[0] || "";
126+
cliFlags = remainingArgs.slice(separatorIndex + 1);
127+
} else {
128+
projectPath = remainingArgs[0] || "";
129+
if (remainingArgs.length > 1) {
130+
printError(`Unexpected argument: ${remainingArgs[1]}`);
131+
usage();
132+
}
118133
}
119134
} else {
120135
printError(`Unknown command: ${firstArg}`);
@@ -156,7 +171,7 @@ async function main(): Promise<void> {
156171
return;
157172
case "run":
158173
case "":
159-
await runContainer(resolvedPath);
174+
await runContainer(resolvedPath, cliFlags);
160175
return;
161176
}
162177
}

0 commit comments

Comments
 (0)