forked from todogroup/repolinter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_exists.js
More file actions
32 lines (29 loc) · 851 Bytes
/
command_exists.js
File metadata and controls
32 lines (29 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2017 TODO Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
const commandExistsLib = require('command-exists')
/**
* Checks whether or not a list of commands exists in the
* current environment. Returns the first command that was
* found to exist.
*
* @protected
* @param {string|string[]} command The command or commands to check for.
* @returns {Promise<string|null>} The first command found to exist, or null of none were found.
* @ignore
*/
async function commandExists(command) {
// convert to array if needed
if (!Array.isArray(command)) {
command = [command]
}
for (const commandString of command) {
try {
await commandExistsLib(commandString)
return commandString
} catch (e) {
// do nothing
}
}
return null
}
module.exports.commandExists = commandExists