mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Fixes #45576: Allow users to control quoting in tasks
This commit is contained in:
@@ -638,6 +638,7 @@ export function createApiFactory(
|
||||
TaskGroup: extHostTypes.TaskGroup,
|
||||
ProcessExecution: extHostTypes.ProcessExecution,
|
||||
ShellExecution: extHostTypes.ShellExecution,
|
||||
ShellQuoting: extHostTypes.ShellQuoting,
|
||||
TaskScope: extHostTypes.TaskScope,
|
||||
Task: extHostTypes.Task,
|
||||
ConfigurationTarget: extHostTypes.ConfigurationTarget,
|
||||
|
||||
@@ -278,20 +278,43 @@ namespace CommandOptions {
|
||||
}
|
||||
}
|
||||
|
||||
namespace ShellQuoteOptions {
|
||||
export function from(value: vscode.ShellQuotingOptions): TaskSystem.ShellQuotingOptions {
|
||||
if (value === void 0 || value === null) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
escape: value.escape,
|
||||
strong: value.strong,
|
||||
weak: value.strong
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace ShellConfiguration {
|
||||
export function from(value: { executable?: string, shellArgs?: string[] }): TaskSystem.ShellConfiguration {
|
||||
export function from(value: { executable?: string, shellArgs?: string[], quotes?: vscode.ShellQuotingOptions }): TaskSystem.ShellConfiguration {
|
||||
if (value === void 0 || value === null || !value.executable) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let result: TaskSystem.ShellConfiguration = {
|
||||
executable: value.executable,
|
||||
args: Strings.from(value.shellArgs)
|
||||
args: Strings.from(value.shellArgs),
|
||||
quoting: ShellQuoteOptions.from(value.quotes)
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ShellString {
|
||||
export function from(value: (string | vscode.ShellQuotedString)[]): TaskSystem.CommandString[] {
|
||||
if (value === void 0 || value === null) {
|
||||
return undefined;
|
||||
}
|
||||
return value.slice(0);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Tasks {
|
||||
|
||||
export function from(tasks: vscode.Task[], rootFolder: vscode.WorkspaceFolder, extension: IExtensionDescription): TaskSystem.ContributedTask[] {
|
||||
@@ -396,18 +419,34 @@ namespace Tasks {
|
||||
}
|
||||
|
||||
function getShellCommand(value: vscode.ShellExecution): TaskSystem.CommandConfiguration {
|
||||
if (typeof value.commandLine !== 'string') {
|
||||
return undefined;
|
||||
if (value.args) {
|
||||
if (typeof value.command !== 'string' && typeof value.command.value !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
let result: TaskSystem.CommandConfiguration = {
|
||||
name: value.command,
|
||||
args: ShellString.from(value.args),
|
||||
runtime: TaskSystem.RuntimeType.Shell,
|
||||
presentation: undefined
|
||||
};
|
||||
if (value.options) {
|
||||
result.options = CommandOptions.from(value.options);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
if (typeof value.commandLine !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
let result: TaskSystem.CommandConfiguration = {
|
||||
name: value.commandLine,
|
||||
runtime: TaskSystem.RuntimeType.Shell,
|
||||
presentation: undefined
|
||||
};
|
||||
if (value.options) {
|
||||
result.options = CommandOptions.from(value.options);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
let result: TaskSystem.CommandConfiguration = {
|
||||
name: value.commandLine,
|
||||
runtime: TaskSystem.RuntimeType.Shell,
|
||||
presentation: undefined
|
||||
};
|
||||
if (value.options) {
|
||||
result.options = CommandOptions.from(value.options);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1311,14 +1311,30 @@ export class ProcessExecution implements vscode.ProcessExecution {
|
||||
export class ShellExecution implements vscode.ShellExecution {
|
||||
|
||||
private _commandLine: string;
|
||||
private _command: string | vscode.ShellQuotedString;
|
||||
private _args: (string | vscode.ShellQuotedString)[];
|
||||
private _options: vscode.ShellExecutionOptions;
|
||||
|
||||
constructor(commandLine: string, options?: vscode.ShellExecutionOptions) {
|
||||
if (typeof commandLine !== 'string') {
|
||||
throw illegalArgument('commandLine');
|
||||
constructor(commandLine: string, options?: vscode.ShellExecutionOptions);
|
||||
constructor(command: string | vscode.ShellQuotedString, args: (string | vscode.ShellQuotedString)[], options?: vscode.ShellExecutionOptions);
|
||||
constructor(arg0: string | vscode.ShellQuotedString, arg1?: vscode.ShellExecutionOptions | (string | vscode.ShellQuotedString)[], arg2?: vscode.ShellExecutionOptions) {
|
||||
if (Array.isArray(arg1)) {
|
||||
if (!arg0) {
|
||||
throw illegalArgument('command can\'t be undefined or null');
|
||||
}
|
||||
if (typeof arg0 !== 'string' && typeof arg0.value !== 'string') {
|
||||
throw illegalArgument('command');
|
||||
}
|
||||
this._command = arg0;
|
||||
this._args = arg1 as (string | vscode.ShellQuotedString)[];
|
||||
this._options = arg2;
|
||||
} else {
|
||||
if (typeof arg0 !== 'string') {
|
||||
throw illegalArgument('commandLine');
|
||||
}
|
||||
this._commandLine = arg0;
|
||||
this._options = arg1;
|
||||
}
|
||||
this._commandLine = commandLine;
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
get commandLine(): string {
|
||||
@@ -1332,6 +1348,25 @@ export class ShellExecution implements vscode.ShellExecution {
|
||||
this._commandLine = value;
|
||||
}
|
||||
|
||||
get command(): string | vscode.ShellQuotedString {
|
||||
return this._command;
|
||||
}
|
||||
|
||||
set command(value: string | vscode.ShellQuotedString) {
|
||||
if (typeof value !== 'string' && typeof value.value !== 'string') {
|
||||
throw illegalArgument('command');
|
||||
}
|
||||
this._command = value;
|
||||
}
|
||||
|
||||
get args(): (string | vscode.ShellQuotedString)[] {
|
||||
return this._args;
|
||||
}
|
||||
|
||||
set args(value: (string | vscode.ShellQuotedString)[]) {
|
||||
this._args = value || [];
|
||||
}
|
||||
|
||||
get options(): vscode.ShellExecutionOptions {
|
||||
return this._options;
|
||||
}
|
||||
@@ -1341,6 +1376,12 @@ export class ShellExecution implements vscode.ShellExecution {
|
||||
}
|
||||
}
|
||||
|
||||
export enum ShellQuoting {
|
||||
Escape = 1,
|
||||
Strong = 2,
|
||||
Weak = 3
|
||||
}
|
||||
|
||||
export enum TaskScope {
|
||||
Global = 1,
|
||||
Workspace = 2
|
||||
|
||||
Reference in New Issue
Block a user