diff --git a/news/10990.feature.rst b/news/10556.feature.rst similarity index 100% rename from news/10990.feature.rst rename to news/10556.feature.rst diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 3612dc45653..cd1e8a00f63 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -853,13 +853,13 @@ def _handle_no_use_pep517( "of pip is available for download. Implied with --no-index.", ) -warn_about_root_user: Callable[..., Option] = partial( +root_user_action: Callable[..., Option] = partial( Option, - "--no-warn-when-using-as-a-root-user", - dest="warn_about_root_user", - default=True, - action="store_false", - help="Do not warn when used as a root user", + "--root-user-action", + dest="root_user_action", + default="warn", + choices=["warn", "ignore"], + help="Action if pip is run as a root user. By default, a warning message is shown.", ) diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 1a5b40b5684..75c8b143c3e 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -227,7 +227,7 @@ def add_options(self) -> None: self.cmd_opts.add_option(cmdoptions.prefer_binary()) self.cmd_opts.add_option(cmdoptions.require_hashes()) self.cmd_opts.add_option(cmdoptions.progress_bar()) - self.cmd_opts.add_option(cmdoptions.warn_about_root_user()) + self.cmd_opts.add_option(cmdoptions.root_user_action()) index_opts = cmdoptions.make_option_group( cmdoptions.index_group, @@ -464,7 +464,7 @@ def run(self, options: Values, args: List[str]) -> int: self._handle_target_dir( options.target_dir, target_temp_dir, options.upgrade ) - if options.warn_about_root_user: + if options.root_user_action == "warn": warn_if_run_as_root() return SUCCESS diff --git a/src/pip/_internal/commands/uninstall.py b/src/pip/_internal/commands/uninstall.py index 45cf2e7f44b..dea8077e7f5 100644 --- a/src/pip/_internal/commands/uninstall.py +++ b/src/pip/_internal/commands/uninstall.py @@ -54,7 +54,7 @@ def add_options(self) -> None: action="store_true", help="Don't ask for confirmation of uninstall deletions.", ) - self.cmd_opts.add_option(cmdoptions.warn_about_root_user()) + self.cmd_opts.add_option(cmdoptions.root_user_action()) self.parser.insert_option_group(0, self.cmd_opts) def run(self, options: Values, args: List[str]) -> int: @@ -101,6 +101,6 @@ def run(self, options: Values, args: List[str]) -> int: ) if uninstall_pathset: uninstall_pathset.commit() - if options.warn_about_root_user: + if options.root_user_action == "warn": warn_if_run_as_root() return SUCCESS