]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
add usage with option
authorBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 14:18:08 +0000 (16:18 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 14:18:08 +0000 (16:18 +0200)
src/albentohandy
tests/albentohandy.bats

index b8e181bfe286469a3c571b5f622b9d92b4bb9282..787553c5e9eb38106cd5d84991ff379b0a66aa05 100755 (executable)
@@ -9,6 +9,19 @@ errlog()
        return $lastexit
 }
 
+useage()
+{
+       echo "NAME"
+       echo "    albentohandy - convert flac to ogg, mp3, opus or flac from music collection"
+       echo "SYNOPSIS"
+       echo "    albentohandy [-3fho]"
+       echo "OPTIONS"
+       echo "    -3    convert to mp3"
+       echo "    -f    convert to flac with cover"
+       echo "    -h    show this usage"
+       echo "    -o    convert to opus"
+}
+
 check_programs()
 {
        command -v rsync > /dev/null \
@@ -101,10 +114,11 @@ main()
        check_programs || return $?
        load_config || return $?
 
-       while getopts "3fi:o" opt; do
+       while getopts "3fhi:o" opt; do
                case "$opt" in
                "3") lib="mp3.sh" ;;
                "f") lib="flac.sh" ;;
+               "h") useage && return 0 ;;
                "i") albumlist="$OPTARG" ;;
                "o") lib="opus.sh" ;;
                *) errlog "unknown option" && return 1 ;;
index 1ff0cbea9c682b73a380e4ab1a8ab82c6c24b627..6c97421974d33d914b0883b9ae46e2ab6c6f824b 100755 (executable)
@@ -339,4 +339,20 @@ teardown() {
        assert_equal "$(awk 'NR==2 {print; exit}' "build/tests/output/checksum.sha256")" "5ca47f5787b6cba8809184876e8557f8650d92c2b7c63a03d1a9b9aa352f7aae  ./Artist1/Album1/02.ogg"
        assert_equal "$(awk 'NR==3 {print; exit}' "build/tests/output/checksum.sha256")" "1aaea6c72ae66ce6bd36cd08fb511565a34179780d68166515a9f045652088c2  ./Artist1/Album1/bla.ogg"
        assert_equal "$(awk 'NR==4 {print; exit}' "build/tests/output/checksum.sha256")" "96af1c6d5c863aef68cabe54aefc2342e66a9cf6b5663660f2ea8cea86e9f5ce  ./Artist1/Album1/blub.ogg"
+}
+
+# bats test_tags=albentohandy:usage
+@test "success: print usage" {
+       run main -h
+
+       assert_success
+       assert_line --index 0 "NAME"
+       assert_line --index 1 "    albentohandy - convert flac to ogg, mp3, opus or flac from music collection"
+       assert_line --index 2 "SYNOPSIS"
+       assert_line --index 3 "    albentohandy [-3fho]"
+       assert_line --index 4 "OPTIONS"
+       assert_line --index 5 "    -3    convert to mp3"
+       assert_line --index 6 "    -f    convert to flac with cover"
+       assert_line --index 7 "    -h    show this usage"
+       assert_line --index 8 "    -o    convert to opus"
 }
\ No newline at end of file