Skip to content

Commit 27f48aa

Browse files
committed
Restore parser state after hiding general options
1 parent e6030b0 commit 27f48aa

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

pip/basecommand.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,25 @@ def parse_args(self, args):
105105
# factored out for testability
106106
return self.parser.parse_args(args)
107107

108-
def print_help(self):
109-
# factored out for uniform handling
110-
# of 'help <command>' and '<command> --help' cases
111-
self.parser.print_help()
108+
def print_help(self, verbose=False):
109+
"""
110+
Process 'help <command>' and '<command> --help' to hide global
111+
options unless --verbose flag is specified.
112+
113+
'pip --help' is handled separately by pip.__init__.parseopt()
114+
"""
115+
if verbose:
116+
self.parser.print_help()
117+
else:
118+
# remove General Options group and restore after print
119+
saveepy = self.parser.epilog
120+
saveogr = self.parser.option_groups # it is a list
121+
self.parser.epilog = "\nAdd '-v' flag to show general "\
122+
"options.\n"
123+
self.parser.option_groups.remove(self.gen_opts)
124+
self.parser.print_help()
125+
self.parser.epilog = saveepy
126+
self.parser.option_groups = saveogr
112127

113128
def main(self, args):
114129
options, args = self.parse_args(args)
@@ -132,16 +147,7 @@ def main(self, args):
132147
root_level = "DEBUG"
133148

134149
if options.help:
135-
if not options.verbose:
136-
# hide General Options
137-
self.parser.epilog = "\nAdd '-v' flag to show general "\
138-
"options.\n"
139-
self.parser.option_groups.remove(self.gen_opts)
140-
141-
# 'pip --help' is handled by pip.__init__.parseopt(),
142-
# so it is not affected by absence of --verbose
143-
144-
self.print_help()
150+
self.print_help(options.verbose)
145151
sys.exit(0)
146152

147153
logging.config.dictConfig({

0 commit comments

Comments
 (0)