mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
mkdir: Use ArgParser, support creating multiple directories
This commit is contained in:
parent
8d419c1915
commit
6fd7966d81
Notes:
sideshowbarker
2024-07-19 07:14:42 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/6fd7966d81e Pull-request: https://github.com/SerenityOS/serenity/pull/1985
2 changed files with 18 additions and 17 deletions
|
@ -1,16 +1,16 @@
|
||||||
## Name
|
## Name
|
||||||
|
|
||||||
mkdir - create a directory
|
mkdir - create directories
|
||||||
|
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
```**sh
|
```**sh
|
||||||
$ mkdir path
|
$ mkdir directories...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
Create a new empty directory at the given *path*.
|
Create a new empty directory for each of the given *directories*.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -24,11 +25,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -39,14 +36,18 @@ int main(int argc, char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 2) {
|
Vector<const char*> directories;
|
||||||
printf("usage: mkdir <path>\n");
|
|
||||||
return 1;
|
Core::ArgsParser args_parser;
|
||||||
}
|
args_parser.add_positional_argument(directories, "Directories to create", "directories");
|
||||||
int rc = mkdir(argv[1], 0755);
|
args_parser.parse(argc, argv);
|
||||||
if (rc < 0) {
|
|
||||||
|
bool has_errors = false;
|
||||||
|
for (auto& directory : directories) {
|
||||||
|
if (mkdir(directory, 0755) < 0) {
|
||||||
perror("mkdir");
|
perror("mkdir");
|
||||||
return 1;
|
has_errors = true;
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return has_errors ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue