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 | |
| 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.
| -rwxr-xr-x | mkhint | 24 | ||||
| -rw-r--r-- | mkhint.bash-completion | 2 |
2 files changed, 19 insertions, 7 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 diff --git a/mkhint.bash-completion b/mkhint.bash-completion index 8c52fb1..29e2523 100644 --- a/mkhint.bash-completion +++ b/mkhint.bash-completion @@ -8,7 +8,7 @@ _mkhintfile_completions() { repo_dir="/var/lib/sbopkg/SBo-danix" hint_dir="/etc/slackrepo/SBo-danix/hintfiles" - local all_flags="--version --hintfile --new --list --clean --delete --no-dl --help" + local all_flags="--version -v --hintfile -f --new -n --list -l --clean -c --delete -d --no-dl -N --help -h" case "$prev" in --new|-n) |
