From 4ed50190e2db9fe45cf9682f94fd6a898b9dfdcf Mon Sep 17 00:00:00 2001 From: sinscary Date: Mon, 24 Feb 2020 14:28:53 +0530 Subject: [PATCH] Raise error if --user and --target arguments are used together --- news/7249.feature | 1 + src/pip/_internal/cli/main_parser.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 news/7249.feature diff --git a/news/7249.feature b/news/7249.feature new file mode 100644 index 00000000000..4548aa006e2 --- /dev/null +++ b/news/7249.feature @@ -0,0 +1 @@ +Raise error if --user and --target are used together in command diff --git a/src/pip/_internal/cli/main_parser.py b/src/pip/_internal/cli/main_parser.py index 4871956c9de..9fd3af49e9b 100644 --- a/src/pip/_internal/cli/main_parser.py +++ b/src/pip/_internal/cli/main_parser.py @@ -83,6 +83,17 @@ def parse_command(args): # the subcommand name cmd_name = args_else[0] + validate_command_args(cmd_name, args_else) + + # all the args without the subcommand + cmd_args = args[:] + cmd_args.remove(cmd_name) + + return cmd_name, cmd_args + + +def validate_command_args(cmd_name, args_else): + # type: (str, List[str]) -> None if cmd_name not in commands_dict: guess = get_similar_commands(cmd_name) @@ -92,8 +103,6 @@ def parse_command(args): raise CommandError(' - '.join(msg)) - # all the args without the subcommand - cmd_args = args[:] - cmd_args.remove(cmd_name) - - return cmd_name, cmd_args + if set(['--user', '--target']).issubset(set(args_else)): + error_msg = '--user and --target cant not be used together.' + raise CommandError(error_msg)