mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
cp: Use LibCore/CArgsParser for command-line arg parsing
This commit is contained in:
parent
3f05799e41
commit
4bc6c20091
1 changed files with 11 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/CArgsParser.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
@ -9,12 +10,18 @@
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 3) {
|
||||
printf("usage: cp <source> <destination>\n");
|
||||
CArgsParser args_parser("cp");
|
||||
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;
|
||||
}
|
||||
String src_path = argv[1];
|
||||
String dst_path = argv[2];
|
||||
String src_path = values[0];
|
||||
String dst_path = values[1];
|
||||
|
||||
int src_fd = open(src_path.characters(), O_RDONLY);
|
||||
if (src_fd < 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue