fix getopt behavior

This commit is contained in:
fatalerrors
2026-03-10 11:40:37 +01:00
parent 02a1e25df2
commit 0a4206b890
2 changed files with 68 additions and 59 deletions

View File

@@ -45,20 +45,22 @@ ver()
return 1 return 1
fi fi
eval set -- "$PARSED" eval set -- "$PARSED"
case "$1" in while true; do
-h|--help) case "$1" in
printf "ver: Display the current profile version.\nUsage: ver\n" -h|--help)
return 0 printf "ver: Display the current profile version.\nUsage: ver\n"
;; return 0
--) ;;
shift --)
break shift
;; break
*) ;;
disp E "Invalid options, use \"ver --help\" to display usage." *)
return 1 disp E "Invalid options, use \"ver --help\" to display usage."
;; return 1
esac ;;
esac
done
[[ -z $PROFVERSION ]] && \ [[ -z $PROFVERSION ]] && \
disp W "No version defined. Profile is probably badly installed." && \ disp W "No version defined. Profile is probably badly installed." && \
@@ -80,20 +82,22 @@ meteo()
return 1 return 1
fi fi
eval set -- "$PARSED" eval set -- "$PARSED"
case "$1" in while true; do
-h|--help) case "$1" in
printf "meteo: Fetch weather data.\nUsage: meteo [city1 city2 ...]\n" -h|--help)
return 0 printf "meteo: Fetch weather data.\nUsage: meteo [city1 city2 ...]\n"
;; return 0
--) ;;
shift --)
break shift
;; break
*) ;;
disp E "Invalid options, use \"meteo --help\" to display usage." *)
return 1 disp E "Invalid options, use \"meteo --help\" to display usage."
;; return 1
esac ;;
esac
done
local cities=("$@") local cities=("$@")
[[ $# -eq 0 ]] && cities=("$DEFAULT_CITY") [[ $# -eq 0 ]] && cities=("$DEFAULT_CITY")
@@ -119,20 +123,23 @@ showinfo()
return 1 return 1
fi fi
eval set -- "$PARSED" eval set -- "$PARSED"
case "$1" in while true; do
-h|--help) case "$1" in
printf "showinfo: Display system information (hostname, kernel, uptime).\nUsage: showinfo\n" -h|--help)
return 0 printf "showinfo: Display system information (hostname, kernel, uptime).\nUsage: showinfo\n"
;; return 0
--) ;;
shift --)
break shift
;; break
*) ;;
disp E "Invalid options, use \"showinfo --help\" to display usage." *)
return 1 disp E "Invalid options, use \"showinfo --help\" to display usage."
;; return 1
esac ;;
esac
done
printf "\n" printf "\n"
if command -v figlet >/dev/null 2>&1; then if command -v figlet >/dev/null 2>&1; then
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then

View File

@@ -56,24 +56,26 @@ setlocale()
return 1 return 1
fi fi
eval set -- "$PARSED" eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
printf "setlocale: Configure system environment locale variables.\n\n"
printf "Usage: setlocale <locale>\n\n"
printf "Options:\n"
printf " -h, --help Display this help screen\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"setlocale --help\" to display usage."
return 1
;;
esac
done
case "$1" in
-h|--help)
printf "setlocale: Configure system environment locale variables.\n\n"
printf "Usage: setlocale <locale>\n\n"
printf "Options:\n"
printf " -h, --help Display this help screen\n"
return 0
;;
--)
shift
break
;;
*)
disp E "Invalid options, use \"setlocale --help\" to display usage."
return 1
;;
esac
local loc=$1 local loc=$1
[[ -z $loc ]] && disp E "No locale specified." && return 1 [[ -z $loc ]] && disp E "No locale specified." && return 1