run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
void run() async {
List<String> files = argResults!.rest;
showUsage(files.isEmpty, () => printUsage());
for (String path in files) {
final filePath = path;
final file = File(filePath);
if (!file.existsSync() && !argResults!['force']) {
out("{@red}File '$filePath' not found{@end}");
exit(unableToOpenInputFile);
}
final run = Run();
final deleted = await run.delete(
filePath,
sudo: argResults!['sudo'],
recursive: argResults!['recursive'],
force: argResults!['force'],
);
if (!deleted || file.existsSync() && !argResults!['force']) {
out("{@red}Failed to delete '$filePath'{@end}");
exit(ioError);
}
if (argResults!['verbose']) {
out("{@green}File deleted: '$filePath'{@end}");
}
}
exit(success);
}