mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-06 09:35:41 -05:00
Add static logger class for azdata extension (#11939)
* Add static logger class for arc extension * Fix compile errors * Fix test
This commit is contained in:
@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
|
||||
import * as cp from 'child_process';
|
||||
import * as sudo from 'sudo-prompt';
|
||||
import * as loc from '../localizedConstants';
|
||||
import Logger from './logger';
|
||||
|
||||
/**
|
||||
* Wrapper error for when an unexpected exit code was received
|
||||
@@ -46,11 +47,10 @@ export type ProcessOutput = { stdout: string, stderr: string };
|
||||
* @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 additionalEnvVars Additional environment variables to add to the process environment
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
export async function executeCommand(command: string, args: string[], outputChannel: vscode.OutputChannel, additionalEnvVars?: { [key: string]: string },): Promise<ProcessOutput> {
|
||||
export async function executeCommand(command: string, args: string[], additionalEnvVars?: { [key: string]: string },): Promise<ProcessOutput> {
|
||||
return new Promise((resolve, reject) => {
|
||||
outputChannel.appendLine(loc.executingCommand(command, args));
|
||||
Logger.log(loc.executingCommand(command, args));
|
||||
const stdoutBuffers: Buffer[] = [];
|
||||
const stderrBuffers: Buffer[] = [];
|
||||
const env = Object.assign({}, process.env, additionalEnvVars);
|
||||
@@ -62,14 +62,14 @@ export async function executeCommand(command: string, args: string[], outputChan
|
||||
const stdout = Buffer.concat(stdoutBuffers).toString('utf8').trim();
|
||||
const stderr = Buffer.concat(stderrBuffers).toString('utf8').trim();
|
||||
if (stdout) {
|
||||
outputChannel.appendLine(loc.stdoutOutput(stdout));
|
||||
Logger.log(loc.stdoutOutput(stdout));
|
||||
}
|
||||
if (stderr) {
|
||||
outputChannel.appendLine(loc.stdoutOutput(stderr));
|
||||
Logger.log(loc.stdoutOutput(stderr));
|
||||
}
|
||||
if (code) {
|
||||
const err = new ExitCodeError(code, stderr);
|
||||
outputChannel.appendLine(err.message);
|
||||
Logger.log(err.message);
|
||||
reject(err);
|
||||
} else {
|
||||
resolve({ stdout: stdout, stderr: stderr });
|
||||
@@ -83,22 +83,21 @@ export async function executeCommand(command: string, args: string[], outputChan
|
||||
* 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<ProcessOutput> {
|
||||
export async function executeSudoCommand(command: string): Promise<ProcessOutput> {
|
||||
return new Promise((resolve, reject) => {
|
||||
outputChannel.appendLine(loc.executingCommand(`sudo ${command}`, []));
|
||||
Logger.log(loc.executingCommand(`sudo ${command}`, []));
|
||||
sudo.exec(command, { name: vscode.env.appName }, (error, stdout, stderr) => {
|
||||
stdout = stdout?.toString() ?? '';
|
||||
stderr = stderr?.toString() ?? '';
|
||||
if (stdout) {
|
||||
outputChannel.appendLine(loc.stdoutOutput(stdout));
|
||||
Logger.log(loc.stdoutOutput(stdout));
|
||||
}
|
||||
if (stderr) {
|
||||
outputChannel.appendLine(loc.stdoutOutput(stderr));
|
||||
Logger.log(loc.stdoutOutput(stderr));
|
||||
}
|
||||
if (error) {
|
||||
outputChannel.appendLine(loc.unexpectedCommandError(error.message));
|
||||
Logger.log(loc.unexpectedCommandError(error.message));
|
||||
reject(error);
|
||||
} else {
|
||||
resolve({ stdout: stdout, stderr: stderr });
|
||||
|
||||
Reference in New Issue
Block a user