Made command line options more POSIX-like.

This commit is contained in:
Shy 2024-08-04 00:54:54 +02:00
parent 4ff0369e76
commit 3081b16a22

37
wled
View file

@ -6,9 +6,28 @@
# Author: Shy # Author: Shy
# License: CC0 # License: CC0
COMMAND="wled"
VERSION="0.0.1"
print_usage() { print_usage() {
echo "Usage: $0 f(nordcenter)|w(ohnzimmer) on|off|1-17|list" echo "\
echo " $0 f(nordcenter)|w(ohnzimmer) b(rightness) 1-255" Usage: $COMMAND -f|-w [on|off]
$COMMAND -f|-w [1-17|list]
$COMMAND -f|-w -b [1-255]"
}
print_help() {
print_usage
echo "
host selection:
-f,--fnordcenter select fnordcenter
-w,--wohnzimmer select wohnzimmer
commands:
on|off switch on/off
[1-17] switch preset
l, list list presets
-b,--brightness [1-255] set brightness"
} }
curl_cmd() { curl_cmd() {
@ -17,14 +36,18 @@ curl_cmd() {
# Parse host argument. # Parse host argument.
case "$1" in case "$1" in
""|-h|--h) # Missing host parameter. ""|-h|--help) # Missing host parameter.
print_usage print_help
exit 0 exit 0
;; ;;
f|fnordcenter) -v|--version)
echo "wled.sh version $VERSION"
exit 0
;;
-f|--fnordcenter)
wled_host='wled-fnordcenter.local' wled_host='wled-fnordcenter.local'
;; ;;
w|wohnzimmer) -w|--wohnzimmer)
wled_host='wled-wohnzimmer.local' wled_host='wled-wohnzimmer.local'
;; ;;
*) # Unknown host parameter. *) # Unknown host parameter.
@ -42,7 +65,7 @@ case "$2" in
off) # Switch off. off) # Switch off.
api_resp=$(curl_cmd --json '{"on":false}' "http://$wled_host/json") api_resp=$(curl_cmd --json '{"on":false}' "http://$wled_host/json")
;; ;;
b|brightness) # Set brightness. -b|--brightness) # Set brightness.
if test -z "$3"; then if test -z "$3"; then
echo "Error: missing parameter for brightness." >&2 echo "Error: missing parameter for brightness." >&2
exit 1 exit 1