2023-04-12 16:11:43 +00:00
|
|
|
#include <os/ArgumentParser.h>
|
2023-04-13 16:33:43 +00:00
|
|
|
#include <os/FileSystem.h>
|
2023-04-12 16:11:43 +00:00
|
|
|
|
2023-04-13 15:04:59 +00:00
|
|
|
Result<int> luna_main(int argc, char** argv)
|
2023-04-12 16:11:43 +00:00
|
|
|
{
|
|
|
|
StringView path;
|
2023-04-19 16:20:44 +00:00
|
|
|
bool recursive;
|
2023-04-12 16:11:43 +00:00
|
|
|
|
|
|
|
os::ArgumentParser parser;
|
2023-04-19 17:16:45 +00:00
|
|
|
parser.add_description("Remove a path from the file system."_sv);
|
2023-04-28 14:33:05 +00:00
|
|
|
parser.add_system_program_info("rm"_sv);
|
2023-04-12 16:11:43 +00:00
|
|
|
parser.add_positional_argument(path, "path"_sv, true);
|
2023-04-19 17:16:45 +00:00
|
|
|
parser.add_switch_argument(recursive, 'r', "recursive"_sv,
|
|
|
|
"remove a directory recursively (by default, rm removes only empty directories)"_sv);
|
2023-04-12 16:11:43 +00:00
|
|
|
parser.parse(argc, argv);
|
|
|
|
|
2023-04-19 16:20:44 +00:00
|
|
|
if (!recursive) TRY(os::FileSystem::remove(path));
|
|
|
|
else
|
|
|
|
TRY(os::FileSystem::remove_tree(path));
|
2023-04-13 15:04:59 +00:00
|
|
|
|
|
|
|
return 0;
|
2023-04-12 16:11:43 +00:00
|
|
|
}
|