diff --git a/packages/salesforcedx-utils/src/cli/checkCliVersion.ts b/packages/salesforcedx-utils/src/cli/checkCliVersion.ts index 0fd35bb5eb..880b1e39a4 100644 --- a/packages/salesforcedx-utils/src/cli/checkCliVersion.ts +++ b/packages/salesforcedx-utils/src/cli/checkCliVersion.ts @@ -5,10 +5,10 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -// import { CliCommandExecutor } from './cliCommandExecutor'; -// import { CommandOutput } from './commandOutput'; -// import { SfCommandBuilder } from './sfCommandBuilder'; -// import { SfdxCommandBuilder } from './sfdxCommandBuilder'; +import { CliCommandExecutor } from './cliCommandExecutor'; +import { CommandOutput } from './commandOutput'; +import { SfCommandBuilder } from './sfCommandBuilder'; +import { SfdxCommandBuilder } from './sfdxCommandBuilder'; export enum CheckCliEnum { validCli = 1, @@ -20,11 +20,35 @@ export enum CheckCliEnum { export class CheckCliVersion { public async getSfdxCliVersion(): Promise { - return 'result1'; + try { + // Execute the command "sfdx --version" in the Terminal + const sfdxExecution = new CliCommandExecutor( + new SfdxCommandBuilder().withArg('--version').withJson().build(), + {} + ).execute(); + // Save the result of the command + const sfdxCmdOutput = new CommandOutput(); + const sfdxVersion = await sfdxCmdOutput.getCmdResult(sfdxExecution); + return sfdxVersion; + } catch { + return 'No SFDX CLI'; + } } public async getSfCliVersion(): Promise { - return 'result2'; + try { + // Execute the command "sf --version" in the Terminal + const sfExecution = new CliCommandExecutor( + new SfCommandBuilder().withArg('--version').withJson().build(), + {} + ).execute(); + // Save the result of the command + const sfCmdOutput = new CommandOutput(); + const sfVersion = await sfCmdOutput.getCmdResult(sfExecution); + return sfVersion; + } catch { + return 'No SF CLI'; + } } public async parseSfdxCliVersion(sfdxCliVersion: string): Promise {