fix(cli): preserve optional argument boundaries

This commit is contained in:
2026-10-30 10:55:34 -03:00
parent b48be5b7b7
commit 97cb71eb80
4 changed files with 152 additions and 32 deletions
+22 -13
View File
@@ -371,7 +371,9 @@ cmd_monitor() {
while [ $# -gt 0 ]; do
case "$1" in
install|uninstall) args+=("$1"); shift ;;
--webhook) webhook="$2"; shift 2 ;;
--webhook)
if [ $# -lt 2 ] || [ -z "$2" ]; then error_exit "--webhook requires a URL"; fi
webhook="$2"; shift 2 ;;
*) args+=("$1"); shift ;;
esac
done
@@ -531,22 +533,29 @@ cmd_interactive_normal() {
}
parse_global_opts() {
local args=()
PARSED_ARGS=()
while [ $# -gt 0 ]; do
case "$1" in
--verbose) VERBOSE=true; shift ;;
--dry-run) DRY_RUN=true; shift ;;
--log-file) LOG_FILE="$2"; shift 2 ;;
*) args+=("$1"); shift ;;
--log-file)
if [ $# -lt 2 ] || [ -z "$2" ]; then error_exit "--log-file requires a path"; fi
case "$2" in --*) error_exit "--log-file requires a path" ;; esac
LOG_FILE="$2"; shift 2 ;;
--) shift; PARSED_ARGS+=("$@"); break ;;
*) PARSED_ARGS+=("$1"); shift ;;
esac
done
set -- "${args[@]}"
echo "$@"
}
main() {
load_config
eval "set -- $(parse_global_opts "$@")"
parse_global_opts "$@"
if [ "${PARSED_ARGS[0]+present}" = present ]; then
set -- "${PARSED_ARGS[@]}"
else
set --
fi
# Per-command help
if [ "${2:-}" = "--help" ] || [ "${2:-}" = "-h" ]; then
@@ -563,7 +572,7 @@ main() {
firewall|fw) cmd_firewall ;;
firewall-off|fw-off) cmd_firewall_off ;;
harden) cmd_harden ;;
audit) cmd_audit "$2" ;;
audit) cmd_audit "${2:-}" ;;
whitelist|wl) cmd_whitelist ;;
backup) cmd_backup ;;
restore) cmd_restore ;;
@@ -581,13 +590,13 @@ main() {
version|-v|--version) cmd_version ;;
init) cmd_init ;;
suggest) cmd_suggest ;;
remediate) cmd_remediate "$2" ;;
predict) cmd_predict "$2" ;;
telemetry) telemetry_opt_in "$2" ;;
remediate) cmd_remediate "${2:-}" ;;
predict) cmd_predict "${2:-}" ;;
telemetry) telemetry_opt_in "${2:-}" ;;
demo) run_demo ;;
update) do_self_update ;;
uninstall) do_uninstall ;;
report) generate_report "$2" ;;
report) generate_report "${2:-}" ;;
config) cmd_config "$@" ;;
vpn-kill) vpn_kill_install "$@" ;;
vpn-kill-remove) vpn_kill_remove ;;
@@ -599,7 +608,7 @@ main() {
install_monitor_launchdaemon ""
success "Reinstall complete"
;;
discord-bot) cmd_discord_bot_install "$2" "$3" ;;
discord-bot) cmd_discord_bot_install "${2:-}" "${3:-}" ;;
discord-bot-stop) cmd_discord_bot_stop ;;
discord-bot-status) cmd_discord_bot_status ;;
help|-h|--help) show_help; exit 0 ;;