diff --git a/src/cli/func-api.ts b/src/cli/func-api.ts index ac8a960..4a98b68 100644 --- a/src/cli/func-api.ts +++ b/src/cli/func-api.ts @@ -142,8 +142,11 @@ export class FuncAPI { return funcCliCommand(deployCommand); } - static runFunc(location: string): CliCommand { + static runFunc(location: string, image: string): CliCommand { const runCommand = ['run', `-p=${location}`, '-v']; + if (image && image.trim().length > 0) { + runCommand.push(`-i=${image}`); + } return funcCliCommand(runCommand); } diff --git a/src/functions/function-command/build-and-deploy-function.ts b/src/functions/function-command/build-and-deploy-function.ts index d59e6c3..c821929 100644 --- a/src/functions/function-command/build-and-deploy-function.ts +++ b/src/functions/function-command/build-and-deploy-function.ts @@ -104,7 +104,7 @@ async function getImageAndBuildStrategy(funcData?: FuncContent, forceImageStrate return { image: imagePick }; } -async function getFunctionImageInteractively( +export async function getFunctionImageInteractively( selectedFolderPick: vscode.Uri, forceImageStrategyPicker?: boolean, ): Promise { diff --git a/src/functions/function-command/run-function.ts b/src/functions/function-command/run-function.ts index ae96def..c5b2acc 100644 --- a/src/functions/function-command/run-function.ts +++ b/src/functions/function-command/run-function.ts @@ -6,12 +6,13 @@ *-----------------------------------------------------------------------------------------------*/ import { window } from 'vscode'; -import { buildFunction, restartBuildCommand } from './build-and-deploy-function'; +import { buildFunction, getFunctionImageInteractively, restartBuildCommand } from './build-and-deploy-function'; import { CliCommand, CliExitData } from '../../cli/cmdCli'; import { FuncAPI } from '../../cli/func-api'; import { telemetryLog } from '../../telemetry'; import { CACHED_CHILDPROCESS, executeCommandInOutputChannels, STILL_EXECUTING_COMMAND } from '../../util/output_channels'; import { FunctionNode } from '../function-tree-view/functionsTreeItem'; +import { ImageAndBuild } from '../function-type'; export const restartRunCommand = new Map(); const delay = (ms) => @@ -22,7 +23,6 @@ const delay = (ms) => async function executeRunCommand(command: CliCommand, context: FunctionNode, name: string): Promise { if (!STILL_EXECUTING_COMMAND.get(name)) { - command.cliArguments.push('--build=false'); await executeCommandInOutputChannels(command, name); if (restartRunCommand.get(context.getName())) { restartRunCommand.set(context.getName(), false); @@ -49,7 +49,6 @@ export async function buildAndRun(context: FunctionNode, command: CliCommand): P if (!STILL_EXECUTING_COMMAND.get(runName) && !STILL_EXECUTING_COMMAND.get(buildName)) { const buildResult: CliExitData = await buildFunction(context); if (buildResult?.stdout) { - command.cliArguments.push('--build=true'); await executeRunCommand(command, context, runName); } return null; @@ -66,13 +65,16 @@ export async function buildAndRun(context: FunctionNode, command: CliCommand): P } } -export async function runFunction(context?: FunctionNode): Promise { +export async function runFunction(context?: FunctionNode, readImage = true): Promise { if (!context) { return null; } telemetryLog('Function_run_command', `Function run command click name: ${context.getName()}`); // TO DO - const command = FuncAPI.runFunc(context.contextPath.fsPath); + const imageAndBuildModel: ImageAndBuild = readImage + ? await getFunctionImageInteractively(context?.contextPath) + : { image: '', builder: '', autoGenerateImage: false }; + const command = FuncAPI.runFunc(context.contextPath.fsPath, imageAndBuildModel.image); const name = `Run: ${context.getName()}`; // const buildName = `Build: ${context.getName()}`; const result = await window.showInformationMessage('Do you want to run with build?', 'Yes', 'No'); diff --git a/test/functions/function-command/run-function.test.ts b/test/functions/function-command/run-function.test.ts index 75251e9..31764ac 100644 --- a/test/functions/function-command/run-function.test.ts +++ b/test/functions/function-command/run-function.test.ts @@ -51,7 +51,7 @@ suite('Function/Run', () => { }); test('delete function from tree view', async () => { - await runFunction(taskRunNode); + await runFunction(taskRunNode, false); // eslint-disable-next-line no-unused-expressions expect(showInformationMessageStub).calledOnce; });