diff --git a/Userland/touch.cpp b/Userland/touch.cpp index 574e97790f4dd6..aadea5d60e8b24 100644 --- a/Userland/touch.cpp +++ b/Userland/touch.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -55,24 +56,28 @@ int main(int argc, char** argv) return 1; } - if (argc != 2) { - fprintf(stderr, "usage: touch \n"); - return 1; - } - if (file_exists(argv[1])) { - int rc = utime(argv[1], nullptr); - if (rc < 0) - perror("utime"); - } else { - int fd = open(argv[1], O_CREAT, 0100644); - if (fd < 0) { - perror("open"); - return 1; - } - int rc = close(fd); - if (rc < 0) { - perror("close"); - return 1; + Vector paths; + + Core::ArgsParser args_parser; + args_parser.add_positional_argument(paths, "Files to touch", "path", Core::ArgsParser::Required::Yes); + args_parser.parse(argc, argv); + + for (auto path : paths) { + if (file_exists(path)) { + int rc = utime(path, nullptr); + if (rc < 0) + perror("utime"); + } else { + int fd = open(path, O_CREAT, 0100644); + if (fd < 0) { + perror("open"); + return 1; + } + int rc = close(fd); + if (rc < 0) { + perror("close"); + return 1; + } } } return 0;