diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-14 10:43:01 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-14 10:43:01 +0200 |
| commit | fed5a05be7d444378a8da5055d720d94e78c15e2 (patch) | |
| tree | 7695ac561fe245e4975c63d3458578af61650193 /mkhint | |
| parent | a35a7805e97b115ae04181dce6cf940e546c7295 (diff) | |
| download | mkhintfile-fed5a05be7d444378a8da5055d720d94e78c15e2.tar.gz mkhintfile-fed5a05be7d444378a8da5055d720d94e78c15e2.zip | |
refactor: switch arg parser to GNU getopt
Enables compound short flags (e.g. -Nn, -Nd). Also add short flags
to bash completion candidates.
Diffstat (limited to 'mkhint')
| -rwxr-xr-x | mkhint | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -314,8 +314,13 @@ clean_bak_files() { # Main function main() { - # Parse command line arguments directly - while [[ $# -gt 0 ]]; do + local parsed + parsed=$(getopt -o v:f:n:lcdNh \ + --long version:,hintfile:,new:,list,clean,delete,no-dl,help \ + -n 'mkhint' -- "$@") || { show_help; exit 1; } + eval set -- "$parsed" + + while true; do case "$1" in --version|-v) VERSION="$2" @@ -338,11 +343,8 @@ main() { shift ;; --delete|-d) + COMMAND="delete" shift - while [[ $# -gt 0 && "$1" != -* ]]; do - DELETE_HINT_FILES+=("$1") - shift - done ;; --no-dl|-N) NO_DL=1 @@ -352,6 +354,10 @@ main() { COMMAND="help" shift ;; + --) + shift + break + ;; *) echo "Unknown option: $1" >&2 show_help @@ -360,6 +366,12 @@ main() { esac done + # Collect remaining positional args as delete targets + while [[ $# -gt 0 ]]; do + DELETE_HINT_FILES+=("$1") + shift + done + if [[ -z "$COMMAND" ]]; then # Default to update hint file if VERSION and HINT_FILE are provided if [[ -n "$VERSION" && -n "$HINT_FILE" ]]; then |
