#compdef bjavaloader

local ret=1
local state cmds


local _bjavaloader_commands
local _bjavaloader_options
local _bjavaloader_dir
local _bjavaloader_erase
local _bjavaloader_wipe


_bjavaloader_commands=(
	'cleareventlog:Clears the handheld event log'
	'deviceinfo:Provides information on the handheld'
	'dir:Lists modules on the handheld'
	'erase:Erase module from handheld'
	'eventlog:Retrieves the handheld event log'
	'load:Loads modules onto the handheld'
	'logstacktraces:Dump the stack traces for all threads to the event log'
	'resettofactory:Reset IT policy to factory defaults'
	'save:Retrieves modules from the handheld'
	'screenshot:Make a screenshot of handheld'
	'settime:Sets the time on the handheld'
	'wipe:Wipes the handheld'
)

_bjavaloader_options=(
	'-h[Show the most relevant command line options]'
	'-p[PIN of device to talk with]:PIN device'
	'-P[Simplistic method to specify device password]:Device password'
	'-v[Dump protocol data during operation]'
	'*::arg:->cmd_or_options'
)

_bjavaloader_dir=(
	'-s[List sibling in module list]'
)

_bjavaloader_erase=(
	'-f[Force to erase an application current running]'
)

_bjavaloader_wipe=(
	'-a[Wipe applications only]'
	'-i[Wipe filesystem only]'
)



declare -A opt_args


_arguments -C -s "$_bjavaloader_options[@]" && return 0


case "$state" in
	cmd_or_options)
		if (( CURRENT == 1)); then
			_describe -t commands 'bjavaloader command' _bjavaloader_commands && ret=0
		else
			case $words[1] in
				cleareventlog)
					_message 'no more arguments' && ret=0
				;;

				deviceinfo)
					_message 'no more arguments' && ret=0
				;;

				dir)
					_message 'no more arguments' && ret=0

					_arguments -C -A '-*' -s \
						"$_bjavaloader_dir[@]" && ret=0
				;;

				erase)
					_message 'modules name from the handheld'

					_arguments -C -A '-*' -s \
						"$_bjavaloader_erase[@]" \
						- recur \
						'*:directory:_path_files -/' \
						- nonrecur \
						'*:COD files:_path_files -g "*.cod(-.)"' && ret=0
				;;

				eventlog)
					_message 'no more arguments' && ret=0
				;;

				load)
					_arguments -C -A '-*' -s \
						- recur \
						'*:directory:_path_files -/' \
						- nonrecur \
						'*:COD files:_path_files -g "*.cod(-.)"' && ret=0
				;;

				logstacktraces)
					_message 'no more arguments' && ret=0
				;;

				save)
					_message 'modules name from the handheld' && ret=0
				;;

				screenshot)
					_arguments -C -A '-*' -s \
						- recur \
						'*:directory:_path_files -/' \
						- nonrecur \
						'*:BMP files:_path_files -g "*.bmp(-.)"' && ret=0
				;;

				settime)
					_message 'time format [yyyy-mm-dd HH:MM:SS]' && ret=0
				;;

				wipe)
					_message 'no more arguments' && ret=0

					_arguments -C -A '-*' -s \
						"$_bjavaloader_wipe[@]" && ret=0
				;;
			esac
		fi
	;;
esac

return ret

