Skip to content

Commit 074d84f

Browse files
Copilotgarrytrinder
andcommitted
Refactor: extract shared Linux prerequisite checks and build command helper
Co-authored-by: garrytrinder <11563347+garrytrinder@users.noreply.github.com>
1 parent 6af4468 commit 074d84f

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

src/commands/install.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,37 @@ async function installOnMac(versionPreference: VersionPreference): Promise<void>
9393
}
9494
}
9595

96-
async function installOnLinux(versionPreference: VersionPreference): Promise<void> {
97-
const scriptUrl = getInstallScriptUrl(versionPreference);
98-
99-
// Check if bash is available
96+
async function checkLinuxPrerequisites(): Promise<boolean> {
10097
try {
10198
await executeCommand('bash --version');
10299
} catch {
103-
vscode.window.showErrorMessage('Bash is not available. Please install bash and try again.');
104-
return;
100+
vscode.window.showErrorMessage('Bash is not available. Please install Bash and try again.');
101+
return false;
105102
}
106103

107-
// Check if curl is available
108104
try {
109105
await executeCommand('curl --version');
110106
} catch {
111107
vscode.window.showErrorMessage('curl is not installed. Please install curl and try again.');
108+
return false;
109+
}
110+
111+
return true;
112+
}
113+
114+
function buildLinuxInstallCommand(scriptUrl: string): string {
115+
return `bash -c "$(curl -sL ${scriptUrl})"`;
116+
}
117+
118+
async function installOnLinux(versionPreference: VersionPreference): Promise<void> {
119+
if (!(await checkLinuxPrerequisites())) {
112120
return;
113121
}
114122

123+
const scriptUrl = getInstallScriptUrl(versionPreference);
124+
115125
try {
116-
await executeCommand(`bash -c "$(curl -sL ${scriptUrl})"`);
126+
await executeCommand(buildLinuxInstallCommand(scriptUrl));
117127
const result = await vscode.window.showInformationMessage('Dev Proxy installed.', 'Reload');
118128
if (result === 'Reload') {
119129
await vscode.commands.executeCommand('workbench.action.reloadWindow');
@@ -130,12 +140,17 @@ async function upgradeDevProxy(configuration: vscode.WorkspaceConfiguration): Pr
130140

131141
// Linux uses install script to upgrade
132142
if (platform === 'linux') {
143+
if (!(await checkLinuxPrerequisites())) {
144+
openUpgradeDocumentation();
145+
return;
146+
}
147+
133148
const scriptUrl = getInstallScriptUrl(versionPreference);
134149
const versionText = isBeta ? 'Dev Proxy Beta' : 'Dev Proxy';
135150
const statusMessage = vscode.window.setStatusBarMessage(`Upgrading ${versionText}...`);
136151

137152
try {
138-
await executeCommand(`bash -c "$(curl -sL ${scriptUrl})"`);
153+
await executeCommand(buildLinuxInstallCommand(scriptUrl));
139154
statusMessage.dispose();
140155

141156
const result = await vscode.window.showInformationMessage(

0 commit comments

Comments
 (0)