@@ -57,7 +57,7 @@ async function ensureTosAccepted(): Promise<boolean> {
5757
5858function usage ( ) : void {
5959 console. log ( `
60- Usage: container [COMMAND] [PROJECT_PATH]
60+ Usage: container [COMMAND] [PROJECT_PATH] [-- DOCKER_FLAGS...]
6161
6262Manage Code containers for isolated project environments.
6363
@@ -73,10 +73,13 @@ Commands:
7373
7474Arguments:
7575 PROJECT_PATH Path to the project directory (defaults to current directory)
76+ DOCKER_FLAGS Additional flags passed to 'docker run' after '--'
7677
7778Examples:
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