Userland: Use Core::ArgsParser for 'basename'

This commit is contained in:
Linus Groh 2020-08-05 22:42:22 +02:00 committed by Andreas Kling
parent 14db94f44b
commit 9b07defb36
Notes: sideshowbarker 2024-07-19 04:11:16 +09:00

View file

@ -25,6 +25,7 @@
*/
#include <AK/LexicalPath.h>
#include <LibCore/ArgsParser.h>
#include <stdio.h>
int main(int argc, char** argv)
@ -34,10 +35,12 @@ int main(int argc, char** argv)
return 1;
}
if (argc != 2) {
printf("usage: basename <path>\n");
return 1;
}
printf("%s\n", LexicalPath(argv[1]).basename().characters());
const char* path = nullptr;
Core::ArgsParser args_parser;
args_parser.add_positional_argument(path, "Path to get basename from", "path");
args_parser.parse(argc, argv);
printf("%s\n", LexicalPath(path).basename().characters());
return 0;
}