#5369 closed (fixed)
Allow commands to register their own options (and refactor help to reflect this)
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Keywords: | command | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
After the refactoring of django.core.management, it was clear that having one universal set of options was less elegant than allowing each command to register just those options it allows. This refactoring keeps exactly the same functionality, but separates out the options. Any subclass of BaseCommand can provide its own option_list (with each option created using optparse.make_option). It inherits all the options in its class hierarchy. (One caveat: BaseCommand subclasses can only extend one superclass. I think handling multiple inheritance is possible, but I'm not sure how much harder it would be and can't think of a reasonable use case that would require it.)
There is a slight backwards incompatibility. django-admin.py --option command
must now be written as django-admin.py command --option
.
Attachments (1)
Change History (9)
by , 17 years ago
Attachment: | command.patch added |
---|
comment:1 by , 17 years ago
This is looking good -- thanks for your work on this, Todd! I'm reviewing the patch now.
comment:3 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 17 years ago
A quick note on the patch: The method of looking at superclasses for different option_list
values seemed a bit strange, so I changed it to make each class responsible to set option_list
"from scratch" (by appending to its superclass' value.
comment:5 by , 17 years ago
Also, I added special-case code for django-admin.py --version
and django-admin.py --help
-- those are too well-known (and standard) to have lost.
follow-up: 7 comment:6 by , 17 years ago
with that patch applied, the development server "crashes" (exiting on SystemExit(0)) instead of reloading on touching a file.
comment:7 by , 17 years ago
Replying to derelm:
with that patch applied, the development server "crashes" (exiting on SystemExit(0)) instead of reloading on touching a file.
i have this same problem. i fixed it temporarily with this bit of a hack:
:django/utils$ svn diff autoreload.py Index: autoreload.py =================================================================== --- autoreload.py (revision 6087) +++ autoreload.py (working copy) @@ -62,7 +62,11 @@ mtimes[filename] = mtime continue if mtime != mtimes[filename]: - sys.exit(3) # force reload + try: + sys.exit(3) # force reload + except Exception: + print 'sys.exit failed, trying os._exit' + os._exit(3) time.sleep(1) def restart_with_reloader():
patch implementing the refactoring