patch: Implement d, --directory option

When given, patch will chdir into the given directory before processing
the patch file.
This commit is contained in:
Shannon Booth 2023-07-14 11:20:03 +12:00 committed by Andrew Kaster
commit 4d8a59f34b
Notes: sideshowbarker 2024-07-17 06:20:50 +09:00

View file

@ -29,9 +29,15 @@ static ErrorOr<void> do_patch(StringView path_of_file_to_patch, Diff::Patch cons
ErrorOr<int> serenity_main(Main::Arguments arguments) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
StringView directory;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.add_option(directory, "Change the working directory to <directory> before applying the patch file", "directory", 'd', "directory");
args_parser.parse(arguments); args_parser.parse(arguments);
if (!directory.is_null())
TRY(Core::System::chdir(directory));
auto input = TRY(Core::File::standard_input()); auto input = TRY(Core::File::standard_input());
auto patch_content = TRY(input->read_until_eof()); auto patch_content = TRY(input->read_until_eof());