|
| 1 | +#compdef manage.py |
| 2 | + |
| 3 | +typeset -ga nul_args |
| 4 | +nul_args=( |
| 5 | + '--settings=-[the Python path to a settings module.]:file:_files' |
| 6 | + '--pythonpath=-[a directory to add to the Python path.]::directory:_directories' |
| 7 | + '--traceback[print traceback on exception.]' |
| 8 | + "--version[show program's version number and exit.]" |
| 9 | + {-h,--help}'[show this help message and exit.]' |
| 10 | +) |
| 11 | + |
| 12 | +_managepy-adminindex(){ |
| 13 | + _arguments -s : \ |
| 14 | + $nul_args \ |
| 15 | + '*::directory:_directories' && ret=0 |
| 16 | +} |
| 17 | + |
| 18 | +_managepy-createcachetable(){ |
| 19 | + _arguments -s : \ |
| 20 | + $nul_args && ret=0 |
| 21 | +} |
| 22 | + |
| 23 | +_managepy-dbshell(){ |
| 24 | + _arguments -s : \ |
| 25 | + $nul_args && ret=0 |
| 26 | +} |
| 27 | + |
| 28 | +_managepy-diffsettings(){ |
| 29 | + _arguments -s : \ |
| 30 | + $nul_args && ret=0 |
| 31 | +} |
| 32 | + |
| 33 | +_managepy-dumpdata(){ |
| 34 | + _arguments -s : \ |
| 35 | + '--format=-[specifies the output serialization format for fixtures.]:format:(json yaml xml)' \ |
| 36 | + '--indent=-[specifies the indent level to use when pretty-printing output.]:' \ |
| 37 | + $nul_args \ |
| 38 | + '*::appname:_applist' && ret=0 |
| 39 | +} |
| 40 | + |
| 41 | +_managepy-flush(){ |
| 42 | + _arguments -s : \ |
| 43 | + '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \ |
| 44 | + '--noinput[tells Django to NOT prompt the user for input of any kind.]' \ |
| 45 | + $nul_args && ret=0 |
| 46 | +} |
| 47 | + |
| 48 | +_managepy-help(){ |
| 49 | + _arguments -s : \ |
| 50 | + '*:command:_managepy_cmds' \ |
| 51 | + $nul_args && ret=0 |
| 52 | +} |
| 53 | + |
| 54 | +_managepy_cmds(){ |
| 55 | + local line |
| 56 | + local -a cmd |
| 57 | + _call_program help-command ./manage.py help \ |
| 58 | + |& sed -n '/^ /s/[(), ]/ /gp' \ |
| 59 | + | while read -A line; do cmd=($line $cmd) done |
| 60 | + _describe -t managepy-command 'manage.py command' cmd |
| 61 | +} |
| 62 | + |
| 63 | +_managepy-inspectdb(){ |
| 64 | + _arguments -s : \ |
| 65 | + $nul_args && ret=0 |
| 66 | +} |
| 67 | + |
| 68 | +_managepy-loaddata(){ |
| 69 | + _arguments -s : \ |
| 70 | + '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \ |
| 71 | + '*::file:_files' \ |
| 72 | + $nul_args && ret=0 |
| 73 | +} |
| 74 | + |
| 75 | +_managepy-reset(){ |
| 76 | + _arguments -s : \ |
| 77 | + '--noinput[tells Django to NOT prompt the user for input of any kind.]' \ |
| 78 | + '*::appname:_applist' \ |
| 79 | + $nul_args && ret=0 |
| 80 | +} |
| 81 | + |
| 82 | +_managepy-runfcgi(){ |
| 83 | + local state |
| 84 | + |
| 85 | + local fcgi_opts |
| 86 | + fcgi_opts=( |
| 87 | + 'protocol[fcgi, scgi, ajp, ... (default fcgi)]:protocol:(fcgi scgi ajp)' |
| 88 | + 'host[hostname to listen on..]:' |
| 89 | + 'port[port to listen on.]:' |
| 90 | + 'socket[UNIX socket to listen on.]::file:_files' |
| 91 | + 'method[prefork or threaded (default prefork)]:method:(prefork threaded)' |
| 92 | + 'maxrequests[number of requests a child handles before it is killed and a new child is forked (0 = no limit).]:' |
| 93 | + 'maxspare[max number of spare processes / threads.]:' |
| 94 | + 'minspare[min number of spare processes / threads.]:' |
| 95 | + 'maxchildren[hard limit number of processes / threads.]:' |
| 96 | + 'daemonize[whether to detach from terminal.]:boolean:(False True)' |
| 97 | + 'pidfile[write the spawned process-id to this file.]:file:_files' |
| 98 | + 'workdir[change to this directory when daemonizing.]:directory:_files' |
| 99 | + 'outlog[write stdout to this file.]:file:_files' |
| 100 | + 'errlog[write stderr to this file.]:file:_files' |
| 101 | + ) |
| 102 | + |
| 103 | + _arguments -s : \ |
| 104 | + $nul_args \ |
| 105 | + '*: :_values "FCGI Setting" $fcgi_opts' && ret=0 |
| 106 | +} |
| 107 | + |
| 108 | +_managepy-runserver(){ |
| 109 | + _arguments -s : \ |
| 110 | + '--noreload[tells Django to NOT use the auto-reloader.]' \ |
| 111 | + '--adminmedia[specifies the directory from which to serve admin media.]:directory:_files' \ |
| 112 | + $nul_args && ret=0 |
| 113 | +} |
| 114 | + |
| 115 | +_managepy-shell(){ |
| 116 | + _arguments -s : \ |
| 117 | + '--plain[tells Django to use plain Python, not IPython.]' \ |
| 118 | + $nul_args && ret=0 |
| 119 | +} |
| 120 | + |
| 121 | +_managepy-sql(){} |
| 122 | +_managepy-sqlall(){} |
| 123 | +_managepy-sqlclear(){} |
| 124 | +_managepy-sqlcustom(){} |
| 125 | +_managepy-sqlflush(){} |
| 126 | +_managepy-sqlindexes(){} |
| 127 | +_managepy-sqlinitialdata(){} |
| 128 | +_managepy-sqlreset(){} |
| 129 | +_managepy-sqlsequencereset(){} |
| 130 | +_managepy-startapp(){} |
| 131 | + |
| 132 | +_managepy-syncdb() { |
| 133 | + _arguments -s : \ |
| 134 | + '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \ |
| 135 | + '--noinput[tells Django to NOT prompt the user for input of any kind.]' \ |
| 136 | + $nul_args && ret=0 |
| 137 | +} |
| 138 | + |
| 139 | +_managepy-test() { |
| 140 | + _arguments -s : \ |
| 141 | + '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \ |
| 142 | + '--noinput[tells Django to NOT prompt the user for input of any kind.]' \ |
| 143 | + '*::appname:_applist' \ |
| 144 | + $nul_args && ret=0 |
| 145 | +} |
| 146 | + |
| 147 | +_managepy-testserver() { |
| 148 | + _arguments -s : \ |
| 149 | + '--verbosity=-[verbosity level; 0=minimal output, 1=normal output, 2=all output.]:Verbosity:((0\:minimal 1\:normal 2\:all))' \ |
| 150 | + '--addrport=-[port number or ipaddr:port to run the server on.]' \ |
| 151 | + '*::fixture:_files' \ |
| 152 | + $nul_args && ret=0 |
| 153 | +} |
| 154 | + |
| 155 | +_managepy-validate() { |
| 156 | + _arguments -s : \ |
| 157 | + $nul_args && ret=0 |
| 158 | +} |
| 159 | + |
| 160 | +_managepy-commands() { |
| 161 | + local -a commands |
| 162 | + |
| 163 | + commands=( |
| 164 | + 'adminindex:prints the admin-index template snippet for the given app name(s).' |
| 165 | + 'createcachetable:creates the table needed to use the SQL cache backend.' |
| 166 | + 'dbshell:runs the command-line client for the current DATABASE_ENGINE.' |
| 167 | + "diffsettings:displays differences between the current settings.py and Django's default settings." |
| 168 | + 'dumpdata:Output the contents of the database as a fixture of the given format.' |
| 169 | + 'flush:Executes ``sqlflush`` on the current database.' |
| 170 | + 'help:manage.py help.' |
| 171 | + 'inspectdb:Introspects the database tables in the given database and outputs a Django model module.' |
| 172 | + 'loaddata:Installs the named fixture(s) in the database.' |
| 173 | + 'reset:Executes ``sqlreset`` for the given app(s) in the current database.' |
| 174 | + 'runfcgi:Run this project as a fastcgi (or some other protocol supported by flup) application,' |
| 175 | + 'runserver:Starts a lightweight Web server for development.' |
| 176 | + 'shell:Runs a Python interactive interpreter.' |
| 177 | + 'sql:Prints the CREATE TABLE SQL statements for the given app name(s).' |
| 178 | + 'sqlall:Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).' |
| 179 | + 'sqlclear:Prints the DROP TABLE SQL statements for the given app name(s).' |
| 180 | + 'sqlcustom:Prints the custom table modifying SQL statements for the given app name(s).' |
| 181 | + 'sqlflush:Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed.' |
| 182 | + 'sqlindexes:Prints the CREATE INDEX SQL statements for the given model module name(s).' |
| 183 | + "sqlinitialdata:RENAMED: see 'sqlcustom'" |
| 184 | + 'sqlreset:Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s).' |
| 185 | + 'sqlsequencereset:Prints the SQL statements for resetting sequences for the given app name(s).' |
| 186 | + "startapp:Creates a Django app directory structure for the given app name in this project's directory." |
| 187 | + "syncdb:Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." |
| 188 | + 'test:Runs the test suite for the specified applications, or the entire site if no apps are specified.' |
| 189 | + 'testserver:Runs a development server with data from the given fixture(s).' |
| 190 | + 'validate:Validates all installed models.' |
| 191 | + ) |
| 192 | + |
| 193 | + _describe -t commands 'manage.py command' commands && ret=0 |
| 194 | +} |
| 195 | + |
| 196 | +_applist() { |
| 197 | + local line |
| 198 | + local -a apps |
| 199 | + _call_program help-command "python -c \"import os.path as op, re, django.conf, sys;\\ |
| 200 | + bn=op.basename(op.abspath(op.curdir));[sys\\ |
| 201 | + .stdout.write(str(re.sub(r'^%s\.(.*?)$' % |
| 202 | + bn, r'\1', i)) + '\n') for i in django.conf.settings.\\ |
| 203 | + INSTALLED_APPS if re.match(r'^%s' % bn, i)]\"" \ |
| 204 | + | while read -A line; do apps=($line $apps) done |
| 205 | + _values 'Application' $apps && ret=0 |
| 206 | +} |
| 207 | + |
| 208 | +_managepy() { |
| 209 | + local curcontext=$curcontext ret=1 |
| 210 | + |
| 211 | + if ((CURRENT == 2)); then |
| 212 | + _managepy-commands |
| 213 | + else |
| 214 | + shift words |
| 215 | + (( CURRENT -- )) |
| 216 | + curcontext="${curcontext%:*:*}:managepy-$words[1]:" |
| 217 | + _call_function ret _managepy-$words[1] |
| 218 | + fi |
| 219 | +} |
| 220 | + |
| 221 | +compdef _managepy manage.py |
| 222 | +compdef _managepy django |
0 commit comments