pypa/pip — pull request #721 by gvalkov (2012-11-10 17:57:44+00:00)
Title: Rework command handling v2

Hi, refactoring guy here again. I decided to resurrect my command line rework patch from a while ago (~9 months). Basically I think that pip's command line interface is not up to par with what you'd expect from Python's flagship package manager. It's quite possibly, the worst one of all package managers that fall in the same category (see [gem](https://gist.github.com/raw/4049959/38023cb622e1718398fc29c13514e7a0ddccb11c/gem.txt), [npm](https://gist.github.com/raw/4049959/ef8dafa1b5bf9c59d30cb233b36b44c54ffb3e47/npm.txt), [luarocks](https://gist.github.com/raw/4049959/7d03fd05720ef71ebd0b1c337a30d2b68692e3d2/lua.txt), [cabal](https://gist.github.com/raw/2701636/5d5621f3e660bcbb931ca0edf2afde0a91543b87/cabal)), in terms of command line look & feel.

In pull requests #463 and #533, I proposed turning pip's cli from [this](https://raw.github.com/gist/2701636/f5757e6fdd6a056483516b832384a95ac8c6597a/old%20pip%20help) to [this](https://raw.github.com/gist/2701636/7581f57849fcd29241f8a4ca6a53018b1127ccb4/new%20pip%20help). This . It's not a big improvement, but it's a start. Unfortunately, I just couldn't bring myself to implementing these without refactoring a few things first and while the general vibe about these changes was positive, very few of the them made it in.

This pull request contains just the refactoring portion of the previous two requests (no ui). To summarize:

- Remove all global command instances and deferred command loading. What replaces them is a command 'registry' (really a mapping of command names to command classes). Commands are instantiated on demand in `pip.__init__.main()`. See `pip.commands.__init__`.

- Remove `baseparser.parser` - the global `OptionParser` instance. Each `Command` instance now receives the main `OptionParser` as its first argument. The main `OptionParser` itself is created with `baseparser.create_main_parser()`.

- Clean up `pip.__init__` by taking option parsing out of `main()`.

Hopefully, this pull request is more 'reviewable' and 'mergeable' than the previous two. The interface changes themselves will come in another round of commits, probably right after I get some assurance that this will get pulled in. Pip has a long pull queue and while this may not be the most important pull of all, some refactoring and attention to detail is long due.

I hope I'm not coming out as arrogant, but I'm concerned about wasting any more time on this, given your track record of accepting my contributions :) I really just want Python to have an excellent package manager.

Cheers,