Skip to content

Commit 4ed5019

Browse files
committed
Raise error if --user and --target arguments are used together
1 parent ea47be5 commit 4ed5019

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

news/7249.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Raise error if --user and --target are used together in command

src/pip/_internal/cli/main_parser.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ def parse_command(args):
8383
# the subcommand name
8484
cmd_name = args_else[0]
8585

86+
validate_command_args(cmd_name, args_else)
87+
88+
# all the args without the subcommand
89+
cmd_args = args[:]
90+
cmd_args.remove(cmd_name)
91+
92+
return cmd_name, cmd_args
93+
94+
95+
def validate_command_args(cmd_name, args_else):
96+
# type: (str, List[str]) -> None
8697
if cmd_name not in commands_dict:
8798
guess = get_similar_commands(cmd_name)
8899

@@ -92,8 +103,6 @@ def parse_command(args):
92103

93104
raise CommandError(' - '.join(msg))
94105

95-
# all the args without the subcommand
96-
cmd_args = args[:]
97-
cmd_args.remove(cmd_name)
98-
99-
return cmd_name, cmd_args
106+
if set(['--user', '--target']).issubset(set(args_else)):
107+
error_msg = '--user and --target cant not be used together.'
108+
raise CommandError(error_msg)

0 commit comments

Comments
 (0)