maximbaz / rebuild-detector

Detects which Arch Linux packages need to be rebuilt
ISC License
214 stars 11 forks source link

minor help tweaks #23

Closed lectrode closed 2 years ago

lectrode commented 2 years ago

not critical, but a nice-to-have

addresses issue #22

cyrinux commented 2 years ago

LGTM, make sense, thanks.

maximbaz commented 2 years ago

Thanks guys, yes makes a lot of sense. Just one question, if we don't add : as the first char of getopts, then we get the desired behavior for unrecognized options by default, correct? Am I not missing anything?

What do you think of this?

--- a/checkrebuild
+++ b/checkrebuild
@@ -9,19 +9,18 @@ shopt -s extglob
 log="$(mktemp -d)"
 trap 'rm -rf "$log"' EXIT

+exit_usage() {
+    echo "Usage: $0 [-v] [-i repo1] [-i repo2]"
+    exit "$1"
+}
+
 verbose=0
-while getopts ":hvi:" OPTION; do
+while getopts "hvi:" OPTION; do
     case $OPTION in
         v) verbose=1 ;;
         i) include+=("$OPTARG") ;;
-        h)
-            echo "Usage: $(basename $0) [-v] [-i repo1] [-i repo2]"
-            exit 0
-            ;;
-        *) echo "Unrecognized parameter: $OPTARG"
-           echo "Usage: $(basename $0) [-v] [-i repo1] [-i repo2]"
-           exit 1
-           ;;
+        h) exit_usage 0 ;;
+        *) exit_usage 1 ;;
     esac
 done

(if so would also drop the basename for consistency with the default behavior)

lectrode commented 2 years ago

I have no objection to those adjustments. Tested, works as expected

maximbaz commented 2 years ago

Ok cool! Let's have your name in the contributors, please apply and I'll merge right away 😉