systemDart function
Executes the system dart cli which is globally available on PATH
Set nothrow
to true to ignore errors when executing the dart command.
The exit code will still be non-zero if the command failed and the method
will still throw if there is no Dart SDK on PATH
If throwOnError
is given and the command returns a non-zero exit code,
the result of throwOnError
will be thrown regardless of nothrow
Implementation
int systemDart(
List<String> args, {
Directory? workingDirectory,
dcli.Progress? progress,
bool nothrow = false,
String Function()? throwOnError,
}) {
final systemDartExecutablePath = systemDartExecutable();
if (systemDartExecutablePath == null) {
throw "Couldn't find dart executable on PATH.";
}
final process = dcli.startFromArgs(
systemDartExecutablePath,
args,
workingDirectory: workingDirectory?.path,
progress: progress,
terminal: progress == null,
nothrow: nothrow || throwOnError != null,
);
final exitCode = process.exitCode ?? -1;
if (exitCode != 0 && throwOnError != null) {
throw throwOnError();
}
return exitCode;
}