mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-13 11:38:36 -05:00
Add extension api for calling azdata commands (#11763)
* Add extension api for calling azdata commands * Update typings file name
This commit is contained in:
@@ -9,15 +9,34 @@ import { HttpClient } from './common/httpClient';
|
||||
import * as loc from './localizedConstants';
|
||||
import { executeCommand, executeSudoCommand } from './common/childProcess';
|
||||
import { searchForCmd } from './common/utils';
|
||||
import { AzdataOutput } from './typings/azdata-ext';
|
||||
|
||||
export const azdataHostname = 'https://aka.ms';
|
||||
export const azdataUri = 'azdata-msi';
|
||||
/**
|
||||
* Information about an azdata installation
|
||||
*/
|
||||
export interface IAzdata {
|
||||
|
||||
export interface IAzdataTool {
|
||||
path: string,
|
||||
version: string
|
||||
version: string,
|
||||
/**
|
||||
* Executes azdata with the specified arguments (e.g. --version) and returns the result
|
||||
* @param args The args to pass to azdata
|
||||
* @param parseResult A function used to parse out the raw result into the desired shape
|
||||
*/
|
||||
executeCommand<R>(args: string[], parseResult: (result: any) => R[]): Promise<AzdataOutput<R>>
|
||||
}
|
||||
|
||||
class AzdataTool implements IAzdataTool {
|
||||
constructor(public path: string, public version: string, private _outputChannel: vscode.OutputChannel) { }
|
||||
|
||||
public async executeCommand<R>(args: string[], parseResult: (result: any) => R[]): Promise<AzdataOutput<R>> {
|
||||
const output = JSON.parse((await executeCommand(`"${this.path}"`, args.concat(['--output', 'json']), this._outputChannel)).stdout);
|
||||
return {
|
||||
logs: <string[]>output.log,
|
||||
stdout: <string[]>output.stdout,
|
||||
stderr: <string[]>output.stderr,
|
||||
result: parseResult(output.result)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,10 +44,10 @@ export interface IAzdata {
|
||||
* or encountered an unexpected error.
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
export async function findAzdata(outputChannel: vscode.OutputChannel): Promise<IAzdata> {
|
||||
export async function findAzdata(outputChannel: vscode.OutputChannel): Promise<IAzdataTool> {
|
||||
outputChannel.appendLine(loc.searchingForAzdata);
|
||||
try {
|
||||
let azdata: IAzdata | undefined = undefined;
|
||||
let azdata: IAzdataTool | undefined = undefined;
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
azdata = await findAzdataWin32(outputChannel);
|
||||
@@ -112,7 +131,7 @@ async function installAzdataLinux(outputChannel: vscode.OutputChannel): Promise<
|
||||
* Finds azdata specifically on Windows
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
async function findAzdataWin32(outputChannel: vscode.OutputChannel): Promise<IAzdata> {
|
||||
async function findAzdataWin32(outputChannel: vscode.OutputChannel): Promise<IAzdataTool> {
|
||||
const promise = searchForCmd('azdata.cmd');
|
||||
return findSpecificAzdata(await promise, outputChannel);
|
||||
}
|
||||
@@ -122,12 +141,9 @@ async function findAzdataWin32(outputChannel: vscode.OutputChannel): Promise<IAz
|
||||
* @param path The path to the azdata executable
|
||||
* @param outputChannel Channel used to display diagnostic information
|
||||
*/
|
||||
async function findSpecificAzdata(path: string, outputChannel: vscode.OutputChannel): Promise<IAzdata> {
|
||||
async function findSpecificAzdata(path: string, outputChannel: vscode.OutputChannel): Promise<IAzdataTool> {
|
||||
const versionOutput = await executeCommand(path, ['--version'], outputChannel);
|
||||
return {
|
||||
path: path,
|
||||
version: parseVersion(versionOutput.stdout)
|
||||
};
|
||||
return new AzdataTool(path, parseVersion(versionOutput.stdout), outputChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user