#-*- mode: shell-script;-*-

# Programmed completion for bash to use moap



_moap_complete_moap_code_test()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_code_test"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_code_test_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_code_test: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_code_develop()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_code_develop"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_code_develop_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_code_develop: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_code()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands="develop test"
    completed=false

    debug "function _moap_complete_moap_code"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_code_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_code: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_changelog_diff()
{
    options="--help --no-entry -E -h"
    optionsboolean="-h --help -E --no-entry"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_changelog_diff"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_changelog_diff_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_changelog_diff: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_changelog_checkin()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_changelog_checkin"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_changelog_checkin_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_changelog_checkin: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_changelog_prepare()
{
    options="--ctags --help -c -h"
    optionsboolean="-h --help -c --ctags"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_changelog_prepare"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_changelog_prepare_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_changelog_prepare: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_changelog_find()
{
    options="--case-sensitive --help -c -h"
    optionsboolean="-h --help -c --case-sensitive"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_changelog_find"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_changelog_find_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_changelog_find: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_changelog_contributors()
{
    options="--help --release -h -r"
    optionsboolean="-h --help"
    optionsvalue="-r --release"
    commands=""
    completed=false

    debug "function _moap_complete_moap_changelog_contributors"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_changelog_contributors_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_changelog_contributors: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_changelog()
{
    options="--ChangeLog --help -C -h"
    optionsboolean="-h --help"
    optionsvalue="-C --ChangeLog"
    commands="checkin contributors diff find prepare"
    completed=false

    debug "function _moap_complete_moap_changelog"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_changelog_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_changelog: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_search()
{
    options="--engine --help --limit -e -h -l"
    optionsboolean="-h --help"
    optionsvalue="-e --engine -l --limit"
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_search"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_search_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_search: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_show()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_show"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_show_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_show: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_ical()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_ical"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_ical_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_ical: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_mail()
{
    options="--dry-run --from --help --release-notes -R -f -h -n"
    optionsboolean="-h --help -n --dry-run"
    optionsvalue="-f --from -R --release-notes"
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_mail"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_mail_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_mail: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_freshmeat()
{
    options="--branch --help --name -b -h -n"
    optionsboolean="-h --help"
    optionsvalue="-b --branch -n --name"
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_freshmeat"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_freshmeat_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_freshmeat: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_bug_query()
{
    options="--format --help --query -f -h -q"
    optionsboolean="-h --help"
    optionsvalue="-q --query -f --format"
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_bug_query"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_bug_query_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_bug_query: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_bug_show()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_bug_show"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_bug_show_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_bug_show: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_bug()
{
    options="--URL --help -U -h"
    optionsboolean="-h --help"
    optionsvalue="-U --URL"
    commands="query show"
    completed=false

    debug "function _moap_complete_moap_doap_bug"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_bug_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_bug: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap_rss()
{
    options="--help --template-language -h -t"
    optionsboolean="-h --help"
    optionsvalue="-t --template-language"
    commands=""
    completed=false

    debug "function _moap_complete_moap_doap_rss"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_rss_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap_rss: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_doap()
{
    options="--file --help --version -f -h -v"
    optionsboolean="-h --help"
    optionsvalue="-f --file -v --version"
    commands="bug freshmeat ical mail rss search show"
    completed=false

    debug "function _moap_complete_moap_doap"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_doap_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_doap: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_ignore()
{
    options="--help --list --no-commit -h -l -n"
    optionsboolean="-h --help -l --list -n --no-commit"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_ignore"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_ignore_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_ignore: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_vcs_backup()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_vcs_backup"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_vcs_backup_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_vcs_backup: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_vcs()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands="backup"
    completed=false

    debug "function _moap_complete_moap_vcs"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_vcs_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_vcs: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_bug_query()
{
    options="--format --help --query -f -h -q"
    optionsboolean="-h --help"
    optionsvalue="-q --query -f --format"
    commands=""
    completed=false

    debug "function _moap_complete_moap_bug_query"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_bug_query_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_bug_query: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_bug_show()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_bug_show"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_bug_show_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_bug_show: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_bug()
{
    options="--URL --help -U -h"
    optionsboolean="-h --help"
    optionsvalue="-U --URL"
    commands="query show"
    completed=false

    debug "function _moap_complete_moap_bug"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_bug_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_bug: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_tracadmin_user_rename()
{
    options="--help --usermap -h -u"
    optionsboolean="-h --help"
    optionsvalue="-u --usermap"
    commands=""
    completed=false

    debug "function _moap_complete_moap_tracadmin_user_rename"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_tracadmin_user_rename_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_tracadmin_user_rename: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_tracadmin_user_list()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands=""
    completed=false

    debug "function _moap_complete_moap_tracadmin_user_list"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_tracadmin_user_list_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_tracadmin_user_list: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_tracadmin_user()
{
    options="--help -h"
    optionsboolean="-h --help"
    optionsvalue=""
    commands="list rename"
    completed=false

    debug "function _moap_complete_moap_tracadmin_user"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_tracadmin_user_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_tracadmin_user: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap_tracadmin()
{
    options="--help --project -h -p"
    optionsboolean="-h --help"
    optionsvalue="-p --project"
    commands="user"
    completed=false

    debug "function _moap_complete_moap_tracadmin"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_tracadmin_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap_tracadmin: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


_moap_complete_moap()
{
    options="--help --version -h -v"
    optionsboolean="-h --help -v --version"
    optionsvalue=""
    commands="bug changelog code doap ignore tracadmin vcs"
    completed=false

    debug "function _moap_complete_moap"
    debug "args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"
    shift
    debug "after shift: args '$@'"
    debug "ARG1 '$1'"
    debug "ARG2 '$2'"


    while [[ "$completed" == "false" ]]
    do
        if [[ "$1" == -* ]]
        then
            # handle as argument
            debug "handling argument $#"
            # found will be set to true when the current argument fully matches
            # an option, causing us to swallow it
            found=false
            # first check for boolean options
            for option in $optionsboolean
            do
                debug "matching option $option to args $1"
                if [[ "$option" == "$1" ]]
                then
                    debug "found full boolean option $option, eating"
                    found=true
                    shift
                fi
            done
            # then check for valued options
            if [[ "$found" == false ]]
            then
                for option in $optionsvalue
                do
                    debug "matching option $option to args $1"
                    if [[ "$option" == "$1" ]]
                    then
                        found=true
                        if [[ $# -eq 1 ]]
                        then
                            # a valued option with no value
                            # we can't complete this since we don't know what
                            # values the option takes
                            completed=true
                            COMPREPLY=()
                        else
                            # eat option and its value
                            shift 2
                        fi
                    fi
                done
            fi
            if [[ "$found" == false ]]
            then
                debug "completing argument"
                COMPREPLY=( $( compgen -W "$options" -- $1 ) )
                debug "COMPREPLY ${COMPREPLY[*]}"
                completed=true
            fi
        else
            # handle as command
            debug "handle as command"
            found=false
            if [[ $# -eq 0 ]]; then
                # completing this command
                COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                debug "command, COMPREPLY ${COMPREPLY[*]}"
                completed=true
            else
                for command in $commands
                do
                    debug "matching arg $1 against command $command"
                    if [[ "$command" == "$1" ]]
                    then
                        debug "found full command, delegating"
                         # completing a subcommand, delegate
                        debug "delegate, $# args, 1 is $1"
                        _moap_complete_moap_$1 $@
                        debug "delegated, COMPREPLY ${COMPREPLY[*]}"
                        found=true
                    fi
                done
                # if not found, we must still be wanting to complete the
                # current partial command
                if [[ "$found" == false ]]
                then
                    COMPREPLY=( $( compgen -W "$commands" -- $1 ) )
                    completed=true
                fi
            fi
        fi
        debug "function _moap_complete_moap: COMPREPLY ${COMPREPLY[*]}"
    done
        
}


# helper debug function
debug()
{
    if [[ ! -z "$DEBUG" ]]
    then
        echo $@
    fi
}

# main entry point
# dispatches to a command-specific function, passing in the rest of the
# command line as arguments, starting with the command name being called
_moap()
{
        COMPREPLY=()
        # pass as a list, not as a single string
        _moap_complete_moap ${COMP_WORDS[*]}
}

complete -F _moap -o default moap

