#-*- mode: shell-script;-*-
_mdb_json()
{
	local cur prev words cword split
	_init_completion -s || return

	if [[ "$prev" == -@(D|-date-format|T|-datetime-format|U|--no-unprintable|h|-help) ]] ; then
		return 0
	fi

	$split && return

	if [[ "$cur" == -* ]]; then
		COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
		[[ $COMPREPLY == *= ]] && compopt -o nospace
	elif [[ "$prev" == *@(mdb|mdw|accdb) ]] ; then
		local dbname
		local tablenames
		dbname=$prev
		__expand_tilde_by_ref dbname
		local IFS=$'\n'
		tablenames="$(eval mdb-tables -S -1 "${dbname}" 2>/dev/null)"
		compopt -o filenames
		COMPREPLY=( $( compgen -W '${tablenames}' -- "$cur" ) )
	else
		_filedir '@(mdb|mdw|accdb)'
	fi
	return 0
} &&
complete -F _mdb_json mdb-json
