#!/bin/sh

BIN="/usr/sbin/self-diagnostics"
. /usr/share/libubox/jshn.sh

case "$1" in
	list)
		echo '{"list": {}, "generate" : {"modules":"String"}}'
	;;
	call)
		case "$2" in
			generate)
				read -t 1 -r input
				local out

				json_load "${input}"
				json_get_var modules modules
				if [ -z "${modules}" ]; then
					out="$(${BIN} -j)"
				else
					out="$(${BIN} -j -m "${modules}")"
				fi
				if [ -z "${out}" ]; then
					echo '{}'
				else
					echo "${out}"
				fi
			;;
			list)
				out="$(${BIN} -j -l)"
				if [ -z "${out}" ]; then
					echo '{}'
				else
					echo "${out}"
				fi
			;;
		esac
	;;
esac
