_gpresult()
{
    local cur prev opts no_value_opts
    _init_completion || return

    no_value_opts="--help --raw --common --verbose --list --previous --user --machine"

    opts="--help --raw --common --verbose --list --previous --width --policy_guid --policy_name --html --user --machine"

    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    local word
    for word in "${COMP_WORDS[@]}"; do
        case "$word" in
            --list|-l)
                opts="--help --raw --common --verbose --list --previous --width --html --user --machine"
                break
                ;;
        esac
    done

    case "$prev" in
        --policy_guid|--policy_name|--width|-w|--html|-H)
            return
            ;;
    esac

    if [[ "$cur" == "-"* ]]; then
        COMPREPLY=($(compgen -W "$opts" -- "$cur"))
    else
        COMPREPLY=($(compgen -W "$no_value_opts" -- "$cur"))
    fi
}

complete -F _gpresult gpresult

