
__validate_url(){

	wget -S --spider $1  2>&1 | grep -q 'HTTP/1.1 200 OK' && return 0
	return 1
}

_voxl_configure_pkg_manager(){

	if ! [ -f /tmp/.known-sections ] ; then
		if __validate_url "http://voxl-packages.modalai.com" ; then
			voxl-get-available-sections >/tmp/.known-sections
			REPO_LIST=( $( cat /tmp/.known-sections ) )
		else
			REPO_LIST=( "dev" "stable" "staging" )
		fi
	else
		REPO_LIST=( $( cat /tmp/.known-sections ) )
	fi

	COMPREPLY=()

	if [ "$COMP_CWORD" -eq 1 ]; then
		COMPREPLY=( $(compgen -W '${REPO_LIST[@]}' -- ${COMP_WORDS[COMP_CWORD]}) )
		return 0
	fi

}

complete -F _voxl_configure_pkg_manager voxl-configure-pkg-manager
