#
# Copyright (c) 2020 Gaël PORTAY
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#

_pacman-system-update()
{
	local cur prev words cword
	_init_completion || return

	for (( i=1; i <= cword - 1; i++ )); do
		if [[ ${words[i]} == -- ]]; then
			# replace the break option -- by the command pacman
			words[i]=pacman
			COMP_WORDS[i]=pacman
			COMP_LINE=${COMP_LINE/-- /pacman }
			(( COMP_POINT += 4 ))

			# insert the pacman operation sync
			COMP_LINE=${COMP_LINE/pacman /pacman -S }
			(( COMP_POINT += 3 ))
			COMP_WORDS=( "${COMP_WORDS[@]:0:i+1}" -S "${COMP_WORDS[@]:i+1}")
			(( COMP_CWORD += 1 ))

			local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
			local root_command=${words[i]}
			_command_offset $i
			return
		fi
	done

	if [[ "$cur" == -* ]]; then
		COMPREPLY=( $( compgen -W "--now --force -V --version -h --help --" -- "$cur" ) )
		return
	fi

	_filedir
} &&
complete -F _pacman-system-update pacman-system-update
