From 93488d6d5afcce8a79eff6c798c26f3152332dfc Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 28 Jun 2022 19:10:31 +0200 Subject: [PATCH] pls: Implement support for `--preserve-env` --- Userland/Utilities/pls.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/pls.cpp b/Userland/Utilities/pls.cpp index 356eff18ff..b11456113d 100644 --- a/Userland/Utilities/pls.cpp +++ b/Userland/Utilities/pls.cpp @@ -17,8 +17,10 @@ ErrorOr serenity_main(Main::Arguments arguments) Vector command; Core::ArgsParser args_parser; uid_t as_user_uid = 0; + bool preserve_env = false; args_parser.set_stop_on_first_non_option(true); args_parser.add_option(as_user_uid, "User to execute as", nullptr, 'u', "UID"); + args_parser.add_option(preserve_env, "Preserve user environment when running command", "preserve-env", 'E'); args_parser.add_positional_argument(command, "Command to run at elevated privilege level", "command"); args_parser.parse(arguments); @@ -53,7 +55,8 @@ ErrorOr serenity_main(Main::Arguments arguments) if (!maybe_needle.has_value()) continue; - if (env_view.substring_view(0, maybe_needle.value()) != "TERM"sv) + // FIXME: Allow a custom selection of variables once ArgsParser supports options with optional parameters. + if (!preserve_env && env_view.substring_view(0, maybe_needle.value()) != "TERM"sv) continue; exec_environment.append(env_view);