mirror of https://github.com/aminya/setup-cpp
feat: add async execRoot
This commit is contained in:
parent
e495d4d0d5
commit
897c5f67c8
|
@ -5,7 +5,7 @@ import which from "which"
|
||||||
let powershell: string | undefined
|
let powershell: string | undefined
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a powershell command.
|
* Asynchronously execute a powershell command.
|
||||||
*
|
*
|
||||||
* @param command The powershell command to execute
|
* @param command The powershell command to execute
|
||||||
* @param startupFlags The optional startup flags to be passed to powershell.
|
* @param startupFlags The optional startup flags to be passed to powershell.
|
||||||
|
|
|
@ -39,3 +39,20 @@ export function execRootSync(
|
||||||
return execa.sync(program, args, execOptions)
|
return execa.sync(program, args, execOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously execute a command as root if sudo is available. Otherwise executes the command normally without sudo.
|
||||||
|
*
|
||||||
|
* @param program The program to spawn
|
||||||
|
* @param args The command arguments
|
||||||
|
* @param execOptions The options passed to `execa`.
|
||||||
|
*
|
||||||
|
* Defaults to `{ stdio: "inherit" }`
|
||||||
|
*/
|
||||||
|
export function execRoot(program: string, args: string[] = [], execOptions: execa.Options = { stdio: "inherit" }) {
|
||||||
|
if (isSudo()) {
|
||||||
|
return execa.command(`sudo ${[program, ...args].map((arg) => `'${arg}'`).join(" ")}`, execOptions)
|
||||||
|
} else {
|
||||||
|
return execa(program, args, execOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue