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)
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
configuration files and environmental variables"""
@ -188,7 +199,7 @@ try:
except pkg_resources.DistributionNotFound:
# when running pip.py without installing
version = None
def create_main_parser():
parser_kw = {

View File

@ -37,7 +37,7 @@ class FreezeCommand(Command):
default=False,
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):
logger.move_stdout_to_stderr()

View File

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

View File

@ -25,7 +25,7 @@ class SearchCommand(Command):
default='http://pypi.python.org/pypi',
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):
if not args:

View File

@ -18,7 +18,7 @@ class ShowCommand(Command):
default=False,
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):
if not args:

View File

@ -24,7 +24,7 @@ class UninstallCommand(Command):
action='store_true',
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):
requirement_set = RequirementSet(

View File

@ -55,7 +55,7 @@ class ZipCommand(Command):
action='store_true',
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):
"""All the entries of sys.path, possibly restricted by --path"""