diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2020-01-27 20:25:36 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-28 13:50:18 +0100 |
commit | f983dfe319978b47b4c5314df9ea3373e3d69c05 (patch) | |
tree | 27d599f2c30ca6bfbfee6fbc3df98a08f33ac887 /Userland/ln.cpp | |
parent | 92765825358daaed11fa105ca64cf2c7819e5563 (diff) | |
download | serenity-f983dfe319978b47b4c5314df9ea3373e3d69c05.zip |
Userland+Terminal: Port to new CArgsParser API
While at it, also add some niceties and fix some things.
Diffstat (limited to 'Userland/ln.cpp')
-rw-r--r-- | Userland/ln.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Userland/ln.cpp b/Userland/ln.cpp index a1379044b7..c567db7dc9 100644 --- a/Userland/ln.cpp +++ b/Userland/ln.cpp @@ -32,21 +32,18 @@ int main(int argc, char** argv) { - CArgsParser args_parser("ln"); + bool symbolic = false; + const char* target = nullptr; + const char* path = nullptr; - args_parser.add_arg("s", "create a symlink"); - args_parser.add_required_single_value("target"); - args_parser.add_required_single_value("link-path"); + CArgsParser args_parser; + args_parser.add_option(symbolic, "Create a symlink", "symbolic", 's'); + args_parser.add_positional_argument(target, "Link target", "target"); + args_parser.add_positional_argument(path, "Link path", "path"); + args_parser.parse(argc, argv); - CArgsParserResult args = args_parser.parse(argc, argv); - Vector<String> values = args.get_single_values(); - if (values.size() == 0) { - args_parser.print_usage(); - return 0; - } - - if (args.is_present("s")) { - int rc = symlink(values[0].characters(), values[1].characters()); + if (symbolic) { + int rc = symlink(target, path); if (rc < 0) { perror("symlink"); return 1; @@ -54,7 +51,7 @@ int main(int argc, char** argv) return 0; } - int rc = link(values[0].characters(), values[1].characters()); + int rc = link(target, path); if (rc < 0) { perror("link"); return 1; |