Luna/apps/rm.cpp
apio 80914f0bb9
All checks were successful
continuous-integration/drone/push Build is passing
ArgumentParser: Add support for version information
2023-04-28 16:33:05 +02:00

23 lines
693 B
C++

#include <os/ArgumentParser.h>
#include <os/FileSystem.h>
Result<int> luna_main(int argc, char** argv)
{
StringView path;
bool recursive;
os::ArgumentParser parser;
parser.add_description("Remove a path from the file system."_sv);
parser.add_system_program_info("rm"_sv);
parser.add_positional_argument(path, "path"_sv, true);
parser.add_switch_argument(recursive, 'r', "recursive"_sv,
"remove a directory recursively (by default, rm removes only empty directories)"_sv);
parser.parse(argc, argv);
if (!recursive) TRY(os::FileSystem::remove(path));
else
TRY(os::FileSystem::remove_tree(path));
return 0;
}