@@ -12,11 +12,15 @@ import { quickPickWorkspaceFolder } from '../../utils/quickPickWorkspaceFolder';
1212import { selectComposeCommand } from '../selectCommandTemplate' ;
1313import { getComposeProfileList , getComposeProfilesOrServices , getComposeServiceList } from './getComposeSubsetList' ;
1414
15- async function compose ( context : IActionContext , commands : ( 'up' | 'down' | 'upSubset' ) [ ] , message : string , dockerComposeFileUri ?: vscode . Uri , selectedComposeFileUris ?: vscode . Uri [ ] ) : Promise < void > {
15+ async function compose ( context : IActionContext , commands : ( 'up' | 'down' | 'upSubset' ) [ ] , message : string , dockerComposeFileUri ?: vscode . Uri | string , selectedComposeFileUris ?: vscode . Uri [ ] , preselectedServices ?: string [ ] , preselectedProfiles ?: string [ ] ) : Promise < void > {
1616 if ( ! vscode . workspace . isTrusted ) {
1717 throw new UserCancelledError ( 'enforceTrust' ) ;
1818 }
1919
20+ if ( typeof dockerComposeFileUri === 'string' ) {
21+ dockerComposeFileUri = vscode . Uri . parse ( dockerComposeFileUri ) ;
22+ }
23+
2024 // If a file is chosen, get its workspace folder, otherwise, require the user to choose
2125 // If a file is chosen that is not in a workspace, it will automatically fall back to quickPickWorkspaceFolder
2226 const folder : vscode . WorkspaceFolder = ( dockerComposeFileUri ? vscode . workspace . getWorkspaceFolder ( dockerComposeFileUri ) : undefined ) ||
@@ -59,7 +63,7 @@ async function compose(context: IActionContext, commands: ('up' | 'down' | 'upSu
5963 ) ;
6064
6165 // Add the service list if needed
62- terminalCommand . command = await addServicesOrProfilesIfNeeded ( context , folder , terminalCommand . command ) ;
66+ terminalCommand . command = await addServicesOrProfilesIfNeeded ( context , folder , terminalCommand . command , preselectedServices , preselectedProfiles ) ;
6367
6468 const client = await ext . orchestratorManager . getClient ( ) ;
6569 const taskCRF = new TaskCommandRunnerFactory ( {
@@ -72,12 +76,14 @@ async function compose(context: IActionContext, commands: ('up' | 'down' | 'upSu
7276 }
7377}
7478
75- export async function composeUp ( context : IActionContext , dockerComposeFileUri ?: vscode . Uri , selectedComposeFileUris ?: vscode . Uri [ ] ) : Promise < void > {
79+ // The parameters of this function should not be changed without updating the compose language service which uses this command
80+ export async function composeUp ( context : IActionContext , dockerComposeFileUri ?: vscode . Uri | string , selectedComposeFileUris ?: vscode . Uri [ ] ) : Promise < void > {
7681 return await compose ( context , [ 'up' ] , vscode . l10n . t ( 'Choose Docker Compose file to bring up' ) , dockerComposeFileUri , selectedComposeFileUris ) ;
7782}
7883
79- export async function composeUpSubset ( context : IActionContext , dockerComposeFileUri ?: vscode . Uri , selectedComposeFileUris ?: vscode . Uri [ ] ) : Promise < void > {
80- return await compose ( context , [ 'upSubset' ] , vscode . l10n . t ( 'Choose Docker Compose file to bring up' ) , dockerComposeFileUri , selectedComposeFileUris ) ;
84+ // The parameters of this function should not be changed without updating the compose language service which uses this command
85+ export async function composeUpSubset ( context : IActionContext , dockerComposeFileUri ?: vscode . Uri | string , selectedComposeFileUris ?: vscode . Uri [ ] , preselectedServices ?: string [ ] , preselectedProfiles ?: string [ ] ) : Promise < void > {
86+ return await compose ( context , [ 'upSubset' ] , vscode . l10n . t ( 'Choose Docker Compose file to bring up' ) , dockerComposeFileUri , selectedComposeFileUris , preselectedServices , preselectedProfiles ) ;
8187}
8288
8389export async function composeDown ( context : IActionContext , dockerComposeFileUri ?: vscode . Uri , selectedComposeFileUris ?: vscode . Uri [ ] ) : Promise < void > {
@@ -90,18 +96,19 @@ export async function composeRestart(context: IActionContext, dockerComposeFileU
9096
9197const serviceListPlaceholder = / \$ { serviceList} / i;
9298const profileListPlaceholder = / \$ { profileList} / i;
93- async function addServicesOrProfilesIfNeeded ( context : IActionContext , workspaceFolder : vscode . WorkspaceFolder , command : string ) : Promise < string > {
99+ async function addServicesOrProfilesIfNeeded ( context : IActionContext , workspaceFolder : vscode . WorkspaceFolder , command : string , preselectedServices : string [ ] , preselectedProfiles : string [ ] ) : Promise < string > {
94100 const commandWithoutPlaceholders = command . replace ( serviceListPlaceholder , '' ) . replace ( profileListPlaceholder , '' ) ;
101+
95102 if ( serviceListPlaceholder . test ( command ) && profileListPlaceholder . test ( command ) ) {
96103 // If both are present, need to ask
97- const { services, profiles } = await getComposeProfilesOrServices ( context , workspaceFolder , commandWithoutPlaceholders ) ;
104+ const { services, profiles } = await getComposeProfilesOrServices ( context , workspaceFolder , commandWithoutPlaceholders , preselectedServices , preselectedProfiles ) ;
98105 return command
99106 . replace ( serviceListPlaceholder , services )
100107 . replace ( profileListPlaceholder , profiles ) ;
101108 } else if ( serviceListPlaceholder . test ( command ) ) {
102- return command . replace ( serviceListPlaceholder , await getComposeServiceList ( context , workspaceFolder , commandWithoutPlaceholders ) ) ;
109+ return command . replace ( serviceListPlaceholder , await getComposeServiceList ( context , workspaceFolder , commandWithoutPlaceholders , preselectedServices ) ) ;
103110 } else if ( profileListPlaceholder . test ( command ) ) {
104- return command . replace ( profileListPlaceholder , await getComposeProfileList ( context , workspaceFolder , commandWithoutPlaceholders ) ) ;
111+ return command . replace ( profileListPlaceholder , await getComposeProfileList ( context , workspaceFolder , commandWithoutPlaceholders , preselectedProfiles ) ) ;
105112 } else {
106113 return command ;
107114 }
0 commit comments