# Copyright: (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
if type complete &>/dev/null; then
  __completeAgcliCommand() {
    SHELL=bash
    local args completion
    if ! type _get_comp_words_by_ref &>/dev/null; then
      completion="$COMP_CWORD"
      args=("${COMP_WORDS[@]}")
    else
      _get_comp_words_by_ref -n = -n @ -n : -w args -i completion
    fi

    local si="$IFS"
    IFS=$'\n' COMPREPLY=($(COMP_CWORD="$completion" \
      COMP_LINE="$COMP_LINE" \
      COMP_POINT="$COMP_POINT" \
      agcli completion -- "${args[@]}" \
      2>/dev/null)) || return $?
    IFS="$si"

    if [ "$COMPREPLY" = "__agcli_complete_files__" ]; then
      COMPREPLY=($(compgen -f -- "$completion"))
    fi

    if type __ltrim_colon_completions &>/dev/null; then
      __ltrim_colon_completions "${args[completion]}"
    fi
  }
  complete -o default -F __completeAgcliCommand agcli
fi
