From 5331cd38ce238396b792ed7c75e25c24ceb64cf3 Mon Sep 17 00:00:00 2001 From: tauraamui Date: Sun, 28 Jul 2024 23:20:23 +0100 Subject: [PATCH] define flag to disable panic capture and invert default to true and hide enable option from help --- src/main.v | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main.v b/src/main.v index e79b0982..a3656d3d 100644 --- a/src/main.v +++ b/src/main.v @@ -67,23 +67,48 @@ fn frame(mut app App) { struct Options { mut: - log_level string - show_help bool - debug_mode bool - capture_panics bool + log_level string + long_show_help_flag string + short_show_help_flag string + show_help bool + long_debug_mode_flag string + short_debug_mode_flag string + debug_mode bool + long_capture_panics_flag string + short_capture_panics_flag string + capture_panics bool + long_disable_panic_capture_flag string + short_disable_panic_capture_flag string + disable_panic_capture bool } fn resolve_options_from_args(args []string) Options { flags := cmdline.only_options(args) - return Options{ - show_help: "--help" in flags || "-h" in flags - debug_mode: "--debug" in flags || "-d" in flags - capture_panics: "--capturepanics" in flags || "-cp" in flags + mut opts := Options { + long_show_help_flag: "help", + short_show_help_flag: "h", + long_debug_mode_flag: "debug", + short_debug_mode_flag: "d", + long_capture_panics_flag: "capture-panics", + short_capture_panics_flag: "cp", + long_disable_panic_capture_flag: "disable-panic-capture", + short_disable_panic_capture_flag: "dpc" } + + opts.show_help = "--${opts.long_show_help_flag}" in flags || "-${opts.short_show_help_flag}" in flags + opts.debug_mode = "--${opts.long_debug_mode_flag}" in flags || "-${opts.short_debug_mode_flag}" in flags + opts.capture_panics = "--${opts.long_capture_panics_flag}" in flags || "-${opts.short_capture_panics_flag}" in flags + opts.disable_panic_capture = "--${opts.long_disable_panic_capture_flag}" in flags || "-${opts.short_disable_panic_capture_flag}" in flags + + return opts +} + +fn (opts Options) flags_str() string { + return "--${opts.long_show_help_flag} (show help)\n\t--${opts.long_debug_mode_flag} (enable debug log out)\n\t--${opts.long_disable_panic_capture_flag} (disable persistance of panic stack trace output)" } -fn output_help_and_close() { - msg := "./lilly