1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:27:45 +00:00

cp: Use LibCore/CArgsParser for command-line arg parsing

This commit is contained in:
Aaron Malpas 2019-09-07 11:03:16 +10:00 committed by Andreas Kling
parent 3f05799e41
commit 4bc6c20091

View file

@ -1,6 +1,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/FileSystemPath.h> #include <AK/FileSystemPath.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibCore/CArgsParser.h>
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
@ -9,12 +10,18 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc != 3) { CArgsParser args_parser("cp");
printf("usage: cp <source> <destination>\n"); args_parser.add_required_single_value("source");
args_parser.add_required_single_value("destination");
CArgsParserResult args = args_parser.parse(argc, argv);
Vector<String> values = args.get_single_values();
if (values.size() == 0) {
args_parser.print_usage();
return 0; return 0;
} }
String src_path = argv[1]; String src_path = values[0];
String dst_path = argv[2]; String dst_path = values[1];
int src_fd = open(src_path.characters(), O_RDONLY); int src_fd = open(src_path.characters(), O_RDONLY);
if (src_fd < 0) { if (src_fd < 0) {