@@ -23,27 +23,36 @@ async function execDockerCompose(
2323 args : Args ,
2424 kwargs ?: Kwargs
2525) : Promise < string > {
26- return shell ( [ "docker-compose" , "-f" , dcPath , ...parseArgs ( args , kwargs ) ] ) ;
26+ return shell ( [
27+ "docker-compose" ,
28+ "-f" ,
29+ dcPath ,
30+ ...parseArgs ( args , kwargs ) ,
31+ // Adding <&- to prevent interactive mode
32+ "<&-"
33+ ] ) ;
2734}
2835
2936export function dockerComposeUp (
3037 dcPath : string ,
31- options ? : {
38+ options : {
3239 noStart ?: boolean ;
40+ detach ?: boolean ;
3341 forceRecreate ?: boolean ;
42+ timeout ?: number ;
3443 serviceNames ?: string [ ] ;
3544 removeOrphans ?: boolean ;
36- }
45+ } = { }
3746) : Promise < string > {
38- const flags : string [ ] = [ ] ;
39- if ( options ? .noStart ) flags . push ( "--no-start" ) ;
40- else flags . push ( "--detach" ) ;
41- if ( options ?. forceRecreate ) flags . push ( "--force-recreate" ) ;
42- if ( options ?. removeOrphans ) flags . push ( "--remove-orphans" ) ;
43- if ( options ?. serviceNames )
44- for ( const serviceName of options . serviceNames ) flags . push ( serviceName ) ;
45- // Adding <&- to prevent interactive mode
46- return execDockerCompose ( dcPath , [ "up" , ... flags , "<&-" ] ) ;
47+ // --detach is invalid with --no-start
48+ if ( options . noStart ) options . detach = false ;
49+ return execDockerCompose ( dcPath , [ "up" , ... ( options . serviceNames || [ ] ) ] , {
50+ noStart : options . noStart ,
51+ detach : options . detach ?? true ,
52+ forceRecreate : options . forceRecreate ,
53+ timeout : options . timeout ,
54+ removeOrphans : options . removeOrphans
55+ } ) ;
4756}
4857
4958/**
@@ -52,19 +61,19 @@ export function dockerComposeUp(
5261 */
5362export function dockerComposeDown (
5463 dcPath : string ,
55- { volumes , timeout } : { volumes ?: boolean ; timeout ?: number } = { }
64+ options : { volumes ?: boolean ; timeout ?: number } = { }
5665) : Promise < string > {
57- return execDockerCompose ( dcPath , [ "down" ] , { volumes , timeout } ) ;
66+ return execDockerCompose ( dcPath , [ "down" ] , options ) ;
5867}
5968
6069/**
6170 * Removes all containers from a compose project
62- * -f: Don't ask to confirm removal
63- * -s: Stop the containers, if required, before removing
71+ * --force Don't ask to confirm removal
72+ * --stop Stop the containers, if required, before removing
6473 * @param dcPath
6574 */
6675export function dockerComposeRm ( dcPath : string ) : Promise < string > {
67- return execDockerCompose ( dcPath , [ "rm" , "-sf" ] ) ;
76+ return execDockerCompose ( dcPath , [ "rm" ] , { force : true , stop : true } ) ;
6877}
6978
7079export function dockerComposeStart ( dcPath : string ) : Promise < string > {
@@ -76,9 +85,9 @@ export function dockerComposeStart(dcPath: string): Promise<string> {
7685 */
7786export function dockerComposeStop (
7887 dcPath : string ,
79- { timeout } : { timeout ?: number } = { }
88+ options : { timeout ?: number } = { }
8089) : Promise < string > {
81- return execDockerCompose ( dcPath , [ "stop" ] , { timeout } ) ;
90+ return execDockerCompose ( dcPath , [ "stop" ] , options ) ;
8291}
8392
8493export function dockerComposeConfig ( dcPath : string ) : Promise < string > {
@@ -97,11 +106,11 @@ export function dockerStart(
97106}
98107
99108export function dockerStop (
100- containerNames : string | string [ ] ,
101- { time } : { time ?: number } = { }
109+ containerNames : string [ ] ,
110+ options : { time ?: number } = { }
102111) : Promise < string > {
103112 const ids = parseContainerIdArg ( containerNames ) ;
104- return execDocker ( [ "stop" , ...ids ] , { time } ) ;
113+ return execDocker ( [ "stop" , ...ids ] , options ) ;
105114}
106115
107116export function dockerRm (
0 commit comments