1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

move command options before general options

Add a new base parser class 'CustomOptionParser' that provides the
'insert_option_group(idx, *, **)' method for inserting an option group
at a specific position.
This commit is contained in:
Georgi Valkov 2012-12-12 15:06:05 +02:00
parent 4ec46922ff
commit b26cdee1e6
7 changed files with 20 additions and 9 deletions

View file

@ -85,7 +85,18 @@ class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
return optparse.IndentedHelpFormatter.expand_default(self, option) return optparse.IndentedHelpFormatter.expand_default(self, option)
class ConfigOptionParser(optparse.OptionParser): class CustomOptionParser(optparse.OptionParser):
def insert_option_group(self, idx, *args, **kwargs):
"""Insert an OptionGroup at a given position."""
group = self.add_option_group(*args, **kwargs)
self.option_groups.pop()
self.option_groups.insert(idx, group)
return group
class ConfigOptionParser(CustomOptionParser):
"""Custom option parser which updates its defaults by by checking the """Custom option parser which updates its defaults by by checking the
configuration files and environmental variables""" configuration files and environmental variables"""
@ -188,7 +199,7 @@ try:
except pkg_resources.DistributionNotFound: except pkg_resources.DistributionNotFound:
# when running pip.py without installing # when running pip.py without installing
version = None version = None
def create_main_parser(): def create_main_parser():
parser_kw = { parser_kw = {

View file

@ -37,7 +37,7 @@ class FreezeCommand(Command):
default=False, default=False,
help='If in a virtualenv, do not report globally-installed packages') help='If in a virtualenv, do not report globally-installed packages')
self.parser.add_option_group(self.cmd_opts) self.parser.insert_option_group(0, self.cmd_opts)
def setup_logging(self): def setup_logging(self):
logger.move_stdout_to_stderr() logger.move_stdout_to_stderr()

View file

@ -200,8 +200,8 @@ class InstallCommand(Command):
default=None, default=None,
help="Install everything relative to this alternate root directory") help="Install everything relative to this alternate root directory")
self.parser.add_option_group(pypi_opts) self.parser.insert_option_group(0, pypi_opts)
self.parser.add_option_group(cmd_opts) self.parser.insert_option_group(0, cmd_opts)
def _build_package_finder(self, options, index_urls): def _build_package_finder(self, options, index_urls):
""" """

View file

@ -25,7 +25,7 @@ class SearchCommand(Command):
default='http://pypi.python.org/pypi', default='http://pypi.python.org/pypi',
help='Base URL of Python Package Index (default %default)') help='Base URL of Python Package Index (default %default)')
self.parser.add_option_group(self.cmd_opts) self.parser.insert_option_group(0, self.cmd_opts)
def run(self, options, args): def run(self, options, args):
if not args: if not args:

View file

@ -18,7 +18,7 @@ class ShowCommand(Command):
default=False, default=False,
help='Show the full list of installed files for each package') help='Show the full list of installed files for each package')
self.parser.add_option_group(self.cmd_opts) self.parser.insert_option_group(0, self.cmd_opts)
def run(self, options, args): def run(self, options, args):
if not args: if not args:

View file

@ -24,7 +24,7 @@ class UninstallCommand(Command):
action='store_true', action='store_true',
help="Don't ask for confirmation of uninstall deletions.") help="Don't ask for confirmation of uninstall deletions.")
self.parser.add_option_group(self.cmd_opts) self.parser.insert_option_group(0, self.cmd_opts)
def run(self, options, args): def run(self, options, args):
requirement_set = RequirementSet( requirement_set = RequirementSet(

View file

@ -55,7 +55,7 @@ class ZipCommand(Command):
action='store_true', action='store_true',
help='Do not actually perform the zip/unzip operation') help='Do not actually perform the zip/unzip operation')
self.parser.add_option_group(self.cmd_opts) self.parser.insert_option_group(0, self.cmd_opts)
def paths(self): def paths(self):
"""All the entries of sys.path, possibly restricted by --path""" """All the entries of sys.path, possibly restricted by --path"""