MCPcopy Create free account
hub / github.com/Azure/powershell / findInPath

Function findInPath

lib/index.js:3549–3599  ·  view source on GitHub ↗

* Returns a list of all occurrences of the given tool on the system path. * * @returns Promise the paths of the tool

(tool)

Source from the content-addressed store, hash-verified

3547 * @returns Promise<string[]> the paths of the tool
3548 */
3549function findInPath(tool) {
3550 return __awaiter(this, void 0, void 0, function* () {
3551 if (!tool) {
3552 throw new Error("parameter 'tool' is required");
3553 }
3554 // build the list of extensions to try
3555 const extensions = [];
3556 if (ioUtil.IS_WINDOWS && process.env['PATHEXT']) {
3557 for (const extension of process.env['PATHEXT'].split(path.delimiter)) {
3558 if (extension) {
3559 extensions.push(extension);
3560 }
3561 }
3562 }
3563 // if it's rooted, return it if exists. otherwise return empty.
3564 if (ioUtil.isRooted(tool)) {
3565 const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions);
3566 if (filePath) {
3567 return [filePath];
3568 }
3569 return [];
3570 }
3571 // if any path separators, return empty
3572 if (tool.includes(path.sep)) {
3573 return [];
3574 }
3575 // build the list of directories
3576 //
3577 // Note, technically "where" checks the current directory on Windows. From a toolkit perspective,
3578 // it feels like we should not do this. Checking the current directory seems like more of a use
3579 // case of a shell, and the which() function exposed by the toolkit should strive for consistency
3580 // across platforms.
3581 const directories = [];
3582 if (process.env.PATH) {
3583 for (const p of process.env.PATH.split(path.delimiter)) {
3584 if (p) {
3585 directories.push(p);
3586 }
3587 }
3588 }
3589 // find all matches
3590 const matches = [];
3591 for (const directory of directories) {
3592 const filePath = yield ioUtil.tryGetExecutablePath(path.join(directory, tool), extensions);
3593 if (filePath) {
3594 matches.push(filePath);
3595 }
3596 }
3597 return matches;
3598 });
3599}
3600exports.findInPath = findInPath;
3601function readCopyOptions(options) {
3602 const force = options.force == null ? true : options.force;

Callers 1

whichFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…