#compdef transcrypt

_transcrypt() {
	local curcontext="$curcontext" state line
	typeset -A opt_args

	_arguments \
		'(- 1 *)'{-l,--list}'[list encrypted files]' \
		'(- 1 *)'{-s,--show-raw=}'[show raw file]:file:->file' \
		'(- 1 *)'{-e,--export-gpg=}'[export config to gpg recipient]:recipient:' \
		'(- 1 *)'{-v,--version}'[print version]' \
		'(- 1 *)'{-h,--help}'[view help message]' \
		'(-c --cipher -d --display -f --flush-credentials -u --uninstall)'{-c,--cipher=}'[specify encryption cipher]:cipher:->cipher' \
		'(-p --password -d --display -f --flush-credentials -u --uninstall)'{-p,--password=}'[specify encryption password]:password:' \
		'(-y --yes)'{-y,--yes}'[assume yes and accept defaults]' \
		'(-d --display -p --password -c --cipher -r --rekey -u --uninstall)'{-d,--display}'[display current credentials]' \
		'(-r --rekey -d --display -f --flush-credentials -u --uninstall)'{-r,--rekey}'[rekey all encrypted files]' \
		'(-f --flush-credentials -c --cipher -p --password -r --rekey -u --uninstall)'{-f,--flush-credentials}'[flush cached credentials]' \
		'(-F --force -d --display -u --uninstall)'{-F,--force}'[ignore repository clean state]' \
		'(-u --uninstall -c --cipher -d --display -f --flush-credentials -p --password -r --rekey)'{-u,--uninstall}'[uninstall transcrypt]' \
		'(--set-openssl-path -c --cipher -d --display -f --flush-credentials -p --password -r --rekey)'{--set-openssl-path}'[use OpenSSL at this path]' \
		'(--upgrade -c --cipher -d --display -f --flush-credentials -p --password -r --rekey)--upgrade[upgrade transcrypt]' \
		'(-i --import-gpg -c --cipher -p --password -d --display -f --flush-credentials -u --uninstall)'{-i,--import-gpg=}'[import config from gpg file]:file:->file' \
		&& return 0

	case $state in
		cipher)
			ciphers=( ${(f)"$(_call_program available-ciphers openssl list-cipher-commands)"} )
			_describe -t available-ciphers 'available ciphers' ciphers
			;;
		file)
			_path_files
			;;
	esac
}

_transcrypt "$@"

return 1
