Skip to content

Commit 63cd270

Browse files
author
Akos Kitta
committed
Simplified code when deceding which CLI to use.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 35ac731 commit 63cd270

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

arduino-ide-extension/src/node/arduino-cli.ts

+9-24
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,15 @@ export class ArduinoCli {
2626
const buildVersion = await this.spawn(`"${buildCli}"`, ['version']);
2727
const buildShortVersion = (buildVersion.match(version) || [])[0];
2828
this.execPath = buildCli;
29-
try {
30-
const pathCli = await new Promise<string>((resolve, reject) => {
31-
which(cli, (error, path) => {
32-
if (error) {
33-
reject(error);
34-
return;
35-
}
36-
resolve(path);
37-
});
38-
});
39-
if (!pathCli) {
40-
return buildCli;
41-
}
42-
const pathVersion = await this.spawn(`"${pathCli}"`, ['version']);
43-
const pathShortVersion = (pathVersion.match(version) || [])[0];
44-
if (semver.gt(pathShortVersion, buildShortVersion)) {
45-
this.execPath = pathCli;
46-
return pathCli;
47-
}
48-
} catch (error) {
49-
this.logger.warn(`Could not check for Arduino CLI in $PATH, using embedded CLI instead:`, error);
50-
// Any errors here should be safe to ignore, e.g.:
51-
// - Could not search for CLI in $PATH
52-
// - Could not get version of CLI in $PATH
29+
const pathCli = await new Promise<string | undefined>(resolve => which(cli, (error, path) => resolve(error ? undefined : path)));
30+
if (!pathCli) {
31+
return buildCli;
32+
}
33+
const pathVersion = await this.spawn(`"${pathCli}"`, ['version']);
34+
const pathShortVersion = (pathVersion.match(version) || [])[0];
35+
if (semver.gt(pathShortVersion, buildShortVersion)) {
36+
this.execPath = pathCli;
37+
return pathCli;
5338
}
5439
return buildCli;
5540
}

0 commit comments

Comments
 (0)