Adds support for installing azdata on Linux (#11469)

This commit is contained in:
Charles Gagnon
2020-07-22 13:41:52 -07:00
committed by GitHub
parent d086b5b01e
commit a61b85c9ff
5 changed files with 49 additions and 6 deletions

View File

@@ -5,6 +5,7 @@
import * as vscode from 'vscode';
import * as cp from 'child_process';
import * as sudo from 'sudo-prompt';
import * as loc from '../localizedConstants';
/**
@@ -17,7 +18,7 @@ export class ExitCodeError extends Error {
}
/**
*
* Executes the specified command. Throws an error for a non-0 exit code or if stderr receives output
* @param command The command to execute
* @param args Optional args to pass, every arg and arg value must be a separate item in the array
* @param outputChannel Channel used to display diagnostic information
@@ -42,3 +43,25 @@ export async function executeCommand(command: string, args?: string[], outputCha
});
});
}
/**
* Executes a command with admin privileges. The user will be prompted to enter credentials for invocation of
* this function. The exact prompt is platform-dependent.
* @param command The command to execute
* @param args The additional args
* @param outputChannel Channel used to display diagnostic information
*/
export async function executeSudoCommand(command: string, outputChannel?: vscode.OutputChannel): Promise<string> {
return new Promise<string>((resolve, reject) => {
outputChannel?.appendLine(loc.executingCommand(`sudo ${command}`, []));
sudo.exec(command, { name: vscode.env.appName }, (error, stdout, stderr) => {
if (error) {
reject(error);
} else if (stderr) {
reject(stderr.toString('utf8'));
} else {
resolve(stdout ? stdout.toString('utf8') : '');
}
});
});
}