#!/bin/sh
#
# Copyright (C) 2016-2019, 2022 The slide-switch authors
# https://github.com/jefferyto/openwrt-slide-switch
#
# slide-switch is free software, licensed under the GNU General Public License v2.
#

. "/usr/share/slide-switch/functions.sh"

optarg=


set_log "${SLIDE_SWITCH_LOG:-stderr}"
set_verbosity "${SLIDE_SWITCH_VERBOSITY:-notice}"

while true; do
	case $1 in
		--log=*)
			optarg=${1#--log=}
			shift

			[ -n "$optarg" ] || {
				error "missing --log argument"
				show_usage
				exit $ex_usage
			}

			set_log "$optarg" || exit
			;;

		--verbosity=*)
			optarg=${1#--verbosity=}
			shift

			[ -n "$optarg" ] || {
				error "missing --verbosity argument"
				show_usage
				exit $ex_usage
			}

			set_verbosity "$optarg" || exit
			;;

		*)
			break
			;;
	esac
done

info "$me $version"

case $1 in
	init)      do_init ;;
	update)    shift; do_update "$@" ;;
	switch)    do_switch ;;
	position)  do_position "$2" ;;
	clean)     do_clean ;;
	boot)      do_boot "$2" ;;
	--version) do_version ;;
	--help)    show_usage ;;

	*)         error "invalid command \"$1\""; show_usage; exit $ex_usage ;;
esac
