1# This is a bash completion script for celery
2# Redirect it to a file, then source it or copy it to /etc/bash_completion.d
3# to get tab completion. celery must be on your PATH for this to work.
4_celery()
5{
6    local cur basep opts base kval kkey loglevels prevp in_opt controlargs
7    local pools
8    COMPREPLY=()
9    cur="${COMP_WORDS[COMP_CWORD]}"
10    prevp="${COMP_WORDS[COMP_CWORD-1]}"
11    basep="${COMP_WORDS[1]}"
12    opts="worker events beat shell multi amqp status
13          inspect control purge list migrate call result
14          report upgrade flower graph logtool help"
15    fargs="--app= --broker= --loader= --config= --version"
16    dopts="--detach --umask= --gid= --uid= --pidfile=
17           --logfile= --loglevel= --executable="
18    controlargs="--timeout --destination"
19    pools="prefork eventlet gevent solo"
20    loglevels="critical error warning info debug"
21    in_opt=0
22
23    # find the current sub-command, store in basep'
24    for index in $(seq 1 $((${#COMP_WORDS[@]} - 2)))
25    do
26        basep=${COMP_WORDS[$index]}
27        if [ "${basep:0:2}" != "--" ]; then
28            break;
29        fi
30    done
31
32    if [ "${cur:0:2}" == "--" -a "$cur" != "${cur//=}" ]; then
33        in_opt=1
34        kkey="${cur%=*}"
35        kval="${cur#*=}"
36    elif [ "${prevp:0:1}" == "-" ]; then
37        in_opt=1
38        kkey="$prevp"
39        kval="$cur"
40    fi
41
42    if [ $in_opt -eq 1 ]; then
43        case "${kkey}" in
44            --uid|-u)
45                COMPREPLY=( $(compgen -u -- "$kval") )
46                return 0
47            ;;
48            --gid|-g)
49                COMPREPLY=( $(compgen -g -- "$kval") )
50                return 0
51            ;;
52            --pidfile|--logfile|-p|-f|--statedb|-S|-s|--schedule-filename)
53                COMPREPLY=( $(compgen -f -- "$kval") )
54                return 0
55            ;;
56            --workdir)
57                COMPREPLY=( $(compgen -d -- "$kval") )
58                return 0
59            ;;
60            --loglevel|-l)
61                COMPREPLY=( $(compgen -W "$loglevels" -- "$kval") )
62                return 0
63            ;;
64            --pool|-P)
65                COMPREPLY=( $(compgen -W "$pools" -- "$kval") )
66                return 0
67            ;;
68            *)
69            ;;
70        esac
71    fi
72
73    case "${basep}" in
74    worker)
75        COMPREPLY=( $(compgen -W '--concurrency= --pool= --purge --logfile=
76        --loglevel= --hostname= --beat --schedule= --scheduler= --statedb= --events
77        --time-limit= --soft-time-limit= --max-tasks-per-child= --queues=
78        --include= --pidfile= --autoscale $fargs' -- ${cur} ) )
79        return 0
80        ;;
81    inspect)
82        COMPREPLY=( $(compgen -W 'active active_queues ping registered report
83        reserved revoked scheduled stats --help $controlargs $fargs' -- ${cur}) )
84        return 0
85        ;;
86    control)
87        COMPREPLY=( $(compgen -W 'add_consumer autoscale cancel_consumer
88        disable_events enable_events pool_grow pool_shrink
89        rate_limit time_limit --help $controlargs $fargs' -- ${cur}) )
90        return 0
91        ;;
92    multi)
93        COMPREPLY=( $(compgen -W 'start restart stopwait stop show
94        kill names expand get help --quiet --nosplash
95        --verbose --no-color --help $fargs' -- ${cur} ) )
96        return 0
97        ;;
98    amqp)
99        COMPREPLY=( $(compgen -W 'queue.declare queue.purge exchange.delete
100        basic.publish exchange.declare queue.delete queue.bind
101        basic.get --help $fargs' -- ${cur} ))
102        return 0
103        ;;
104    list)
105        COMPREPLY=( $(compgen -W 'bindings $fargs' -- ${cur} ) )
106        return 0
107        ;;
108    shell)
109        COMPREPLY=( $(compgen -W '--ipython --bpython --python
110        --without-tasks --eventlet --gevent $fargs' -- ${cur} ) )
111        return 0
112        ;;
113    beat)
114        COMPREPLY=( $(compgen -W '--schedule= --scheduler=
115        --max-interval= $dopts $fargs' -- ${cur}  ))
116        return 0
117        ;;
118    events)
119        COMPREPLY=( $(compgen -W '--dump --camera= --freq=
120        --maxrate= $dopts $fargs' -- ${cur}))
121        return 0
122        ;;
123    *)
124        ;;
125    esac
126
127   COMPREPLY=($(compgen -W "${opts} ${fargs}" -- ${cur}))
128   return 0
129}
130complete -F _celery celery
131
132