~fwereade/pyjuju/euca-walrus-fix

« back to all changes in this revision

Viewing changes to misc/bash_completion.d/ensemble

  • Committer: Benjamin Saller
  • Date: 2011-07-25 17:39:26 UTC
  • mto: This revision was merged to the branch mainline in revision 282.
  • Revision ID: bcsaller@gmail.com-20110725173926-3rk9xhwdma1a01lr
review changes, spacing, indentation, quoting

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
shopt -s progcomp
2
 
_ensemble ()
3
 
{
4
 
        local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
5
 
        local curOpt optEnums
6
 
        local IFS=$' \n'
7
 
 
8
 
        COMPREPLY=()
9
 
        cur=${COMP_WORDS[COMP_CWORD]}
10
 
 
11
 
        cmds='add-relation add-unit bootstrap debug-hooks debug-log deploy destroy-service expose open-tunnel remove-relation remove-unit resolved set shutdown ssh status terminate-machine unexpose upgrade-formula'
12
 
        globalOpts=( -h --verbose -v --log-file)
13
 
 
14
 
        # do ordinary expansion if we are anywhere after a -- argument
15
 
        for ((i = 1; i < COMP_CWORD; ++i)); do
16
 
                [[ ${COMP_WORDS[i]} == "--" ]] && return 0
17
 
        done
18
 
 
19
 
        # find the command; it's the first word not starting in -
20
 
        cmd=
21
 
        for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
22
 
                if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
23
 
                        cmd=${COMP_WORDS[cmdIdx]}
24
 
                        break
25
 
                fi
26
 
        done
27
 
 
28
 
        # complete command name if we are not already past the command
29
 
        if [[ $COMP_CWORD -le cmdIdx ]]; then
30
 
                COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
31
 
                return 0
32
 
        fi
33
 
 
34
 
        # find the option for which we want to complete a value
35
 
        curOpt=
36
 
        if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
37
 
                curOpt=${COMP_WORDS[COMP_CWORD - 1]}
38
 
                if [[ $curOpt == = ]]; then
39
 
                        curOpt=${COMP_WORDS[COMP_CWORD - 2]}
40
 
                elif [[ $cur == : ]]; then
41
 
                        cur=
42
 
                        curOpt="$curOpt:"
43
 
                elif [[ $curOpt == : ]]; then
44
 
                        curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
45
 
                fi
46
 
        fi
47
 
 
48
 
        cmdOpts=( )
49
 
        optEnums=( )
50
 
        fixedWords=( )
51
 
        case $cmd in
52
 
        add-relation|add-unit|debug-hooks|destory-service|expose-service|unexpose-service|open-tunnel|remove-relation|remove-unit|ssh|terminate-machine)
53
 
                cmdOpts=( --environment )
54
 
                ;;
55
 
        bootstrap)
56
 
                cmdOpts=( )
57
 
                ;;
58
 
        set|deploy)
59
 
                cmdOpts=( --environment --repository )
60
 
                ;;
61
 
        debug-log)
62
 
                cmdOpts=( --environment -e --replay -r -i -x -l -n -o --output)
63
 
        case $curOpt in
64
 
            -l) optEnums=( DEBUG INFO ERROR WARNING CRITICAL ) ;;
65
 
        esac
66
 
                ;;
67
 
    resolved)
68
 
        cmdOpts=( --retry --environment )
69
 
        ;;
70
 
    status)
71
 
        cmdOpts=( --output --format --environment)
72
 
        case $curOpt in
73
 
            --format) optEnums=( json yaml png svg dot )
74
 
        esac
75
 
        ;;
76
 
    upgrade-formula)
 
2
_ensemble () {
 
3
    local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
 
4
    local curOpt optEnums
 
5
    local IFS=$' \n'
 
6
 
 
7
    COMPREPLY=()
 
8
    cur=${COMP_WORDS[COMP_CWORD]}
 
9
    cmds='add-relation add-unit bootstrap debug-hooks debug-log deploy destroy-service expose open-tunnel remove-relation remove-unit resolved set shutdown ssh status terminate-machine unexpose upgrade-formula'
 
10
    globalOpts=( -h --verbose -v --log-file)
 
11
 
 
12
    # do ordinary expansion if we are anywhere after a -- argument
 
13
    for ((i = 1; i < COMP_CWORD; ++i)); do
 
14
        [[ ${COMP_WORDS[i]} == "--" ]] && return 0
 
15
    done
 
16
 
 
17
    # find the command; it's the first word not starting in -
 
18
    cmd=
 
19
    for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
 
20
        if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
 
21
            cmd=${COMP_WORDS[cmdIdx]}
 
22
            break
 
23
        fi
 
24
    done
 
25
 
 
26
    # complete command name if we are not already past the command
 
27
    if [[ $COMP_CWORD -le cmdIdx ]]; then
 
28
        COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- "$cur" ) )
 
29
        return 0
 
30
    fi
 
31
 
 
32
    # find the option for which we want to complete a value
 
33
    curOpt=
 
34
    if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
 
35
        curOpt=${COMP_WORDS[COMP_CWORD - 1]}
 
36
        if [[ "$curOpt" == = ]]; then
 
37
            curOpt=${COMP_WORDS[COMP_CWORD - 2]}
 
38
        elif [[ "$cur" == : ]]; then
 
39
            cur=
 
40
            curOpt="$curOpt:"
 
41
        elif [[ "$curOpt" == : ]]; then
 
42
            curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
 
43
        fi
 
44
    fi
 
45
 
 
46
    cmdOpts=( )
 
47
    optEnums=( )
 
48
    fixedWords=( )
 
49
    case "$cmd" in
 
50
        add-relation|add-unit|debug-hooks|destory-service|expose-service|unexpose-service|open-tunnel|remove-relation|remove-unit|ssh|terminate-machine)
 
51
            cmdOpts=( --environment )
 
52
            ;;
 
53
        bootstrap)
 
54
            cmdOpts=( )
 
55
            ;;
 
56
        set|deploy)
 
57
            cmdOpts=( --environment --repository )
 
58
            ;;
 
59
        debug-log)
 
60
            cmdOpts=( --environment -e --replay -r -i -x -l -n -o --output)
 
61
            case "$curOpt" in
 
62
                -l) optEnums=( DEBUG INFO ERROR WARNING CRITICAL ) ;;
 
63
            esac
 
64
            ;;
 
65
        resolved)
 
66
            cmdOpts=( --retry --environment )
 
67
            ;;
 
68
        status)
 
69
            cmdOpts=( --output --format --environment)
 
70
            case "$curOpt" in
 
71
                --format) optEnums=( json yaml png svg dot )
 
72
            ;;
 
73
            esac
 
74
            ;;
 
75
        upgrade-formula)
77
76
            cmdOpts=( --dry-run -n --environment --repository)
78
 
        ;;
79
 
        *)
80
 
                cmdOpts=(--help -h)
81
 
                ;;
82
 
        esac
83
 
 
84
 
        IFS=$'\n'
85
 
        if [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
86
 
                # complete directly after "--option=", list all enum values
87
 
                COMPREPLY=( "${optEnums[@]}" )
88
 
                return 0
89
 
        else
90
 
                fixedWords=( "${cmdOpts[@]}"
91
 
                             "${globalOpts[@]}"
92
 
                             "${optEnums[@]}"
93
 
                             "${fixedWords[@]}" )
94
 
        fi
95
 
 
96
 
        if [[ ${#fixedWords[@]} -gt 0 ]]; then
97
 
                COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
98
 
        fi
99
 
 
100
 
        return 0
 
77
            ;;
 
78
        *)
 
79
            cmdOpts=(--help -h)
 
80
            ;;
 
81
    esac
 
82
 
 
83
    IFS=$'\n'
 
84
    if [[ "$cur" == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
 
85
        # complete directly after "--option=", list all enum values
 
86
        COMPREPLY=( "${optEnums[@]}" )
 
87
        return 0
 
88
    else
 
89
        fixedWords=( "${cmdOpts[@]}"
 
90
                     "${globalOpts[@]}"
 
91
                     "${optEnums[@]}"
 
92
                     "${fixedWords[@]}" )
 
93
    fi
 
94
 
 
95
    if [[ ${#fixedWords[@]} -gt 0 ]]; then
 
96
        COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- "$cur" ) )
 
97
    fi
 
98
 
 
99
    return 0
101
100
}
102
101
 
103
102
complete -F _ensemble -o default ensemble