simple method
Run a command on the system
If sudo is true, the command will be run with sudo permissions
If onProgress is provided, it will be called with the output of the
command
Implementation
Future<ProcessResult> simple(
String script,
List<String> args, {
void Function(String)? onProgress,
bool quiet = false,
bool sudo = false,
}) async {
final controller = ShellLinesController();
ShellEnvironment env = ShellEnvironment()..aliases['sudo'] = 'sudo --stdin';
Shell shell = Shell(
stdout: controller.sink,
environment: env,
workingDirectory: XPM.userHome.path,
runInShell: true,
commandVerbose: false,
);
if (onProgress != null) {
controller.stream.listen((line) => onProgress.call(line));
} else if (!quiet) {
controller.stream.listen((line) => print('-> $line'));
}
if (sudo) {
return await shell.runExecutableArguments('sudo', [script, ...args]);
} else {
return await shell.runExecutableArguments(script, args);
}
}