Handle special characters from user input for child processes
This commit is contained in:
Родитель
f0c86bcd6b
Коммит
321f8c0710
|
@ -36,8 +36,7 @@ export async function createFunction(outputChannel: vscode.OutputChannel, functi
|
|||
if (missingFiles.length !== 0) {
|
||||
const result = await vscode.window.showWarningMessage(`The current folder is not initialized as a function app. Add missing files: '${missingFiles.join("', '")}'?`, _yes, _no);
|
||||
if (result === _yes) {
|
||||
const output = await functionsCli.initFunctionApp(rootPath);
|
||||
outputChannel.append(output);
|
||||
await functionsCli.initFunctionApp(outputChannel, rootPath);
|
||||
} else {
|
||||
throw new util.UserCancelledError();
|
||||
}
|
||||
|
@ -54,8 +53,7 @@ export async function createFunction(outputChannel: vscode.OutputChannel, functi
|
|||
|
||||
const name = await util.showInputBox("Function Name", "Provide a function name", (s) => validateTemplateName(rootPath, s));
|
||||
|
||||
const output = await functionsCli.createFunction(rootPath, template.label, name);
|
||||
outputChannel.append(output);
|
||||
await functionsCli.createFunction(outputChannel, rootPath, template.label, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,8 +90,7 @@ export async function initFunctionApp(outputChannel: vscode.OutputChannel, funct
|
|||
}
|
||||
|
||||
// TODO: Handle folders that are already initialized
|
||||
const output = await functionsCli.initFunctionApp(functionAppPath);
|
||||
outputChannel.append(output);
|
||||
await functionsCli.initFunctionApp(outputChannel, functionAppPath);
|
||||
}
|
||||
|
||||
export async function startFunctionApp(outputChannel: vscode.OutputChannel, node?: FunctionAppNode) {
|
||||
|
|
|
@ -10,28 +10,25 @@ export class FunctionsCli {
|
|||
constructor(private readonly _terminal: vscode.Terminal) {
|
||||
}
|
||||
|
||||
createFunction(workingDirectory: string, templateName: string, name: string): Promise<string> {
|
||||
return this.executeCommand(workingDirectory, `func new --language JavaScript --template ${templateName} --name ${name}`);
|
||||
async createFunction(outputChannel: vscode.OutputChannel, workingDirectory: string, templateName: string, name: string) {
|
||||
return this.executeCommand(outputChannel, workingDirectory, 'new', '--language', 'JavaScript', '--template', templateName, '--name', name);
|
||||
}
|
||||
|
||||
initFunctionApp(workingDirectory: string): Promise<string> {
|
||||
return this.executeCommand(workingDirectory, `func init`);
|
||||
async initFunctionApp(outputChannel: vscode.OutputChannel, workingDirectory: string) {
|
||||
return this.executeCommand(outputChannel, workingDirectory, 'init');
|
||||
}
|
||||
|
||||
private executeCommand(workingDirectory: string, command: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
private executeCommand(outputChannel: vscode.OutputChannel, workingDirectory: string, ...args: string[]): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options: cp.ExecOptions = {
|
||||
cwd: workingDirectory
|
||||
};
|
||||
// TODO: Verify special characters are escaped properly
|
||||
cp.exec(command, options, (error, stdout, stderr) => {
|
||||
if (stderr) {
|
||||
reject(new Error(stderr));
|
||||
} else if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(stdout);
|
||||
}
|
||||
const childProc = cp.spawn('func', args, options);
|
||||
childProc.stdout.on('data', (data) => outputChannel.append(data.toString()));
|
||||
childProc.stderr.on('data', (data) => reject(new Error(data.toString())));
|
||||
childProc.on('error', error => reject(error));
|
||||
childProc.on('close', code => {
|
||||
code === 0 ? resolve() : reject(new Error(`Command failed with exit code '${code}'.`))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче