From 4d8a59f34beb7ad3540c21b6019885049e46d146 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 14 Jul 2023 11:20:03 +1200 Subject: [PATCH] patch: Implement d, --directory option When given, patch will chdir into the given directory before processing the patch file. --- Userland/Utilities/patch.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Utilities/patch.cpp b/Userland/Utilities/patch.cpp index cba196ffe8..6bb0681adb 100644 --- a/Userland/Utilities/patch.cpp +++ b/Userland/Utilities/patch.cpp @@ -29,9 +29,15 @@ static ErrorOr do_patch(StringView path_of_file_to_patch, Diff::Patch cons ErrorOr serenity_main(Main::Arguments arguments) { + StringView directory; + Core::ArgsParser args_parser; + args_parser.add_option(directory, "Change the working directory to before applying the patch file", "directory", 'd', "directory"); args_parser.parse(arguments); + if (!directory.is_null()) + TRY(Core::System::chdir(directory)); + auto input = TRY(Core::File::standard_input()); auto patch_content = TRY(input->read_until_eof());