Luna/apps/ln.cpp

30 lines
794 B
C++
Raw Normal View History

2023-05-20 19:48:28 +00:00
#include <os/ArgumentParser.h>
#include <stdio.h>
#include <unistd.h>
Result<int> luna_main(int argc, char** argv)
{
StringView target;
StringView linkpath;
bool create_symlink { false };
2023-05-20 19:48:28 +00:00
os::ArgumentParser parser;
parser.add_description("Create links between files.");
2023-05-20 19:48:28 +00:00
parser.add_system_program_info("ln"_sv);
parser.add_positional_argument(target, "target", true);
parser.add_positional_argument(linkpath, "linkpath", true);
parser.add_switch_argument(create_symlink, 's', "symbolic"_sv, "create symlinks instead of hard links"_sv);
2023-05-20 19:48:28 +00:00
parser.parse(argc, argv);
auto link_function = create_symlink ? symlink : link;
if (link_function(target.chars(), linkpath.chars()) < 0)
2023-05-20 19:48:28 +00:00
{
perror("ln");
return 1;
}
return 0;
}