| | 1 | """ |
| | 2 | # Tests for LaxOptionParser in core.management |
| | 3 | |
| | 4 | # The handling of command line options in the management command requires a 2 |
| | 5 | # pass approach; # --settings and --pythonpath must be extracted on the first |
| | 6 | # pass, but on the second pass, --settings and --pythonpath can be ignored. |
| | 7 | # The LaxOptionParser implements the first pass, ignoring any option it |
| | 8 | # doesn't know about, and providing a list of arguments filtered of any |
| | 9 | # --settings or --pythonpath values. Any erroneous settings will be caught by |
| | 10 | # the second pass. |
| | 11 | |
| | 12 | >>> from django.core.management import LaxOptionParser, get_version |
| | 13 | >>> from django.core.management.base import BaseCommand |
| | 14 | >>> parser = LaxOptionParser(version=get_version(), option_list=BaseCommand.option_list) |
| | 15 | |
| | 16 | # Invoke a command with options after the settings and python path |
| | 17 | >>> options, args = parser.parse_args('django-admin.py command --settings=settingsmodule --pythonpath=/home/user/django-dir --option'.split()) |
| | 18 | >>> print options |
| | 19 | {'pythonpath': '/home/user/django-dir', 'settings': 'settingsmodule'} |
| | 20 | >>> args |
| | 21 | ['django-admin.py', 'command', '--option'] |
| | 22 | |
| | 23 | # Invoke a command with options between the settings and python path |
| | 24 | >>> options, args = parser.parse_args('django-admin.py command --settings=settingsmodule --option --pythonpath=/home/user/django-dir'.split()) |
| | 25 | >>> print options |
| | 26 | {'pythonpath': '/home/user/django-dir', 'settings': 'settingsmodule'} |
| | 27 | >>> args |
| | 28 | ['django-admin.py', 'command', '--option'] |
| | 29 | |
| | 30 | # Invoke a command with options between the python path and settings |
| | 31 | >>> options, args = parser.parse_args('django-admin.py command --pythonpath=/home/user/django-dir --option --settings=settingsmodule '.split()) |
| | 32 | >>> print options |
| | 33 | {'pythonpath': '/home/user/django-dir', 'settings': 'settingsmodule'} |
| | 34 | >>> args |
| | 35 | ['django-admin.py', 'command', '--option'] |
| | 36 | |
| | 37 | # Invoke a command with options before the settings and python path |
| | 38 | >>> options, args = parser.parse_args('django-admin.py command --option --settings=settingsmodule --pythonpath=/home/user/django-dir'.split()) |
| | 39 | >>> print options |
| | 40 | {'pythonpath': '/home/user/django-dir', 'settings': 'settingsmodule'} |
| | 41 | >>> args |
| | 42 | ['django-admin.py', 'command', '--option'] |
| | 43 | |
| | 44 | |
| | 45 | """ |
| | 46 | No newline at end of file |