From a758e27153fd06653df095368604c49a9d998056 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sun, 9 Jul 2023 15:27:36 +0100 Subject: [PATCH] ps: Disallow using `-q` with any other filtering options This matches the behavior of `ps` on Linux. --- Userland/Utilities/ps.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/ps.cpp b/Userland/Utilities/ps.cpp index c76b06fea8..6789a6e591 100644 --- a/Userland/Utilities/ps.cpp +++ b/Userland/Utilities/ps.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2023, Sam Atkins + * Copyright (c) 2023, Tim Ledbetter * * SPDX-License-Identifier: BSD-2-Clause */ @@ -80,7 +81,7 @@ ErrorOr serenity_main(Main::Arguments arguments) bool every_process_flag = false; bool every_terminal_process_flag = false; bool full_format_flag = false; - bool provided_pid_list = false; + bool provided_filtering_option = false; bool provided_quick_pid_list = false; Vector pid_list; Vector uid_list; @@ -91,7 +92,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(every_process_flag, "Show every process (Equivalent to -A)", nullptr, 'e'); args_parser.add_option(full_format_flag, "Full format", nullptr, 'f'); args_parser.add_option(make_list_option(pid_list, "Show processes with a matching PID. (Comma- or space-separated list)", nullptr, 'p', "pid-list", [&](StringView pid_string) { - provided_pid_list = true; + provided_filtering_option = true; auto pid = pid_string.to_int(); if (!pid.has_value()) warnln("Could not parse '{}' as a PID.", pid_string); @@ -105,6 +106,7 @@ ErrorOr serenity_main(Main::Arguments arguments) return pid; })); args_parser.add_option(make_list_option(uid_list, "Show processes with a matching user ID or login name. (Comma- or space-separated list.)", nullptr, 'u', "user-list", [&](StringView user_string) -> Optional { + provided_filtering_option = true; if (auto uid = user_string.to_uint(); uid.has_value()) { return uid.value(); } @@ -118,8 +120,8 @@ ErrorOr serenity_main(Main::Arguments arguments) })); args_parser.parse(arguments); - if (provided_pid_list && provided_quick_pid_list) { - warnln("`-p` and `-q` cannot be specified together."); + if (provided_filtering_option && provided_quick_pid_list) { + warnln("The -q option cannot be combined with other filtering options."); return 1; }