#!/bin/bash

# SPDX-FileCopyrightText: 2022 Uniontech Software Technology Co.,Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

_dde_dconfig()
{
    COMPREPLY=()
    local cur=${COMP_WORDS[COMP_CWORD]};
    local cmd=${COMP_WORDS[COMP_CWORD-1]};
    case $cmd in
    'dde-dconfig')
        COMPREPLY=( $(compgen -W '--help --list --set --get --gui' -- $cur) ) ;;
    '-a')
        local result=( $(dde-dconfig --list) )
        COMPREPLY=( $(compgen -W "${result[*]}" -- $cur) ) ;;
    '-r')
        local a=${COMP_WORDS[COMP_CWORD-2]}
        local result=( $(dde-dconfig --list -a $a) )
        COMPREPLY=( $(compgen -W "${result[*]}" -- $cur) ) ;;
    '-k')
        local a=${COMP_WORDS[COMP_CWORD-4]}
        local r=${COMP_WORDS[COMP_CWORD-2]}
        local result=( $(dde-dconfig --get -a $a -r $r) )
        COMPREPLY=( $(compgen -W "${result[*]}" -- $cur) ) ;;
    esac
    return 0
}
complete -F _dde_dconfig dde-dconfig
