30 lines
794 B
C++
30 lines
794 B
C++
#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 };
|
|
|
|
os::ArgumentParser parser;
|
|
parser.add_description("Create links between files.");
|
|
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);
|
|
parser.parse(argc, argv);
|
|
|
|
auto link_function = create_symlink ? symlink : link;
|
|
|
|
if (link_function(target.chars(), linkpath.chars()) < 0)
|
|
{
|
|
perror("ln");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|