Refactor command location and DevChat installation

- Updated the locateCommand function to split the output of the 'where' and 'which' commands and return the first line.
- Modified the DevChat installation command to include the path in quotes to handle paths with spaces.
This commit is contained in:
bobo.yang 2023-07-06 07:42:44 +08:00
parent e6f184cfe6
commit e53b0576b3
2 changed files with 6 additions and 3 deletions

View File

@ -9,10 +9,13 @@ let devchatStatus = '';
function locateCommand(command): string | undefined { function locateCommand(command): string | undefined {
try { try {
return runCommand(`where ${command}`).toString().trim(); // split lines and choose first line
const binPaths = runCommand(`where ${command}`).toString().trim().split('\n');
return binPaths[0].trim();
} catch (error) { } catch (error) {
try { try {
return runCommand(`which ${command}`).toString().trim(); const binPaths = runCommand(`which ${command}`).toString().trim().split('\n');
return binPaths[0].trim();
} catch (error) { } catch (error) {
return undefined; return undefined;
} }

View File

@ -79,7 +79,7 @@ export async function dependencyCheck(): Promise<[string, string]> {
} }
if (devchatStatus === 'not ready') { if (devchatStatus === 'not ready') {
// auto install devchat // auto install devchat
UiUtilWrapper.runTerminal('DevChat Install', `${pythonCommand} ${UiUtilWrapper.extensionPath() + "/tools/install.py"}`); UiUtilWrapper.runTerminal('DevChat Install', `${pythonCommand} "${UiUtilWrapper.extensionPath() + "/tools/install.py"}"`);
devchatStatus = 'Waiting for devchat installation to complete'; devchatStatus = 'Waiting for devchat installation to complete';
isVersionChangeCompare = true; isVersionChangeCompare = true;
} }