diff --git a/news/4433.feature b/news/4433.feature new file mode 100644 index 00000000000..29b16a168f2 --- /dev/null +++ b/news/4433.feature @@ -0,0 +1,2 @@ +Global options are not shown for subcommands unless explicitly requested with +`--verbose`. \ No newline at end of file diff --git a/pip/basecommand.py b/pip/basecommand.py index 510b032381e..266d3d71542 100644 --- a/pip/basecommand.py +++ b/pip/basecommand.py @@ -59,11 +59,11 @@ def __init__(self, isolated=False): self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name) # Add the general options - gen_opts = cmdoptions.make_option_group( + self.gen_opts = cmdoptions.make_option_group( cmdoptions.general_group, self.parser, ) - self.parser.add_option_group(gen_opts) + self.parser.add_option_group(self.gen_opts) def _build_session(self, options, retries=None, timeout=None): session = PipSession( @@ -105,6 +105,26 @@ def parse_args(self, args): # factored out for testability return self.parser.parse_args(args) + def print_help(self, verbose=False): + """ + Process 'help ' and ' --help' to hide global + options unless --verbose flag is specified. + + 'pip --help' is handled separately by pip.__init__.parseopt() + """ + if verbose: + self.parser.print_help() + else: + # remove General Options group and restore after print + saveepy = self.parser.epilog + saveogr = self.parser.option_groups # it is a list + self.parser.epilog = "\nAdd '-v' flag to show general "\ + "options.\n" + self.parser.option_groups.remove(self.gen_opts) + self.parser.print_help() + self.parser.epilog = saveepy + self.parser.option_groups = saveogr + def main(self, args): options, args = self.parse_args(args) @@ -126,6 +146,10 @@ def main(self, args): if options.log: root_level = "DEBUG" + if options.help: + self.print_help(options.verbose) + sys.exit(0) + logging.config.dictConfig({ "version": 1, "disable_existing_loggers": False, diff --git a/pip/cmdoptions.py b/pip/cmdoptions.py index 3f9db5ba5ad..1c06535d9d5 100644 --- a/pip/cmdoptions.py +++ b/pip/cmdoptions.py @@ -63,7 +63,7 @@ def getname(n): Option, '-h', '--help', dest='help', - action='help', + action='store_true', help='Show help.') isolated_mode = partial( diff --git a/pip/commands/help.py b/pip/commands/help.py index e897427d892..98352151ef9 100644 --- a/pip/commands/help.py +++ b/pip/commands/help.py @@ -31,6 +31,6 @@ def run(self, options, args): raise CommandError(' - '.join(msg)) command = commands_dict[cmd_name]() - command.parser.print_help() + command.print_help() return SUCCESS