From 8ab6e7aeec35ce38b1682bf8ed80302cf08a3be5 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Fri, 25 Sep 2026 16:18:08 +0200 Subject: [PATCH] add usage with option --- src/albentohandy | 16 +++++++++++++++- tests/albentohandy.bats | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/albentohandy b/src/albentohandy index b8e181b..787553c 100755 --- a/src/albentohandy +++ b/src/albentohandy @@ -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 ;; diff --git a/tests/albentohandy.bats b/tests/albentohandy.bats index 1ff0cbe..6c97421 100755 --- a/tests/albentohandy.bats +++ b/tests/albentohandy.bats @@ -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 -- 2.47.3