mirror of
https://github.com/alexanderepstein/Bash-Snippets
synced 2018-11-08 02:59:35 +01:00
Updating lyrics to work with filepaths, adding tests for lyrics
This commit is contained in:
parent
38d27ac0b2
commit
ddb840621d
2 changed files with 50 additions and 6 deletions
|
@ -4,6 +4,7 @@ currentVersion="1.18.1"
|
|||
configuredClient=""
|
||||
artist="false"
|
||||
song="false"
|
||||
filePath=""
|
||||
|
||||
## This function determines which http get tool the system has installed and returns an error if there isnt one
|
||||
getConfiguredClient()
|
||||
|
@ -112,16 +113,16 @@ getLyrics()
|
|||
|
||||
printLyrics()
|
||||
{
|
||||
if [ -z $filePath ];then echo -e "$lyrics"
|
||||
if [[ $filePath == "" ]];then echo -e "$lyrics"
|
||||
else
|
||||
if [ -f $filePath ];then
|
||||
if [ -f "$filePath" ];then
|
||||
echo -n "File already exists, do you want to overwrite it [Y/n]: "
|
||||
read -r answer
|
||||
if [[ "$answer" == [Yy] ]]; then
|
||||
echo -e "$lyrics" > $filePath;
|
||||
echo -e "$lyrics" > "$filePath";
|
||||
fi
|
||||
else
|
||||
echo -e "$lyrics" > $filePath;
|
||||
echo -e "$lyrics" > "$filePath";
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -156,20 +157,24 @@ while getopts "f:a:s:uvh" opt; do
|
|||
v) echo "Version $currentVersion"
|
||||
exit 0
|
||||
;;
|
||||
u) checkInternet || exit 1
|
||||
u)
|
||||
getConfiguredClient || exit 1
|
||||
checkInternet || exit 1
|
||||
update
|
||||
exit 0
|
||||
;;
|
||||
f)
|
||||
filePath=$OPTARG
|
||||
filePath="$OPTARG"
|
||||
;;
|
||||
a)
|
||||
artist="true"
|
||||
if [[ "$(echo "$@" | grep -Eo "\-s")" == "-s" ]];then song="true";fi # wont go through both options if arg spaced and not quoted this solves that issue (dont need this but once had bug on system where it was necessary)
|
||||
if [[ "$(echo "$@" | grep -Eo "\-f")" == "-f" ]];then filePath=$(echo "$@" | grep -Eo "\-f [ a-z A-Z / 0-9 . \ ]*[ -]?" | sed s/-f//g | sed s/-//g | sed s/^" "//g);fi
|
||||
;;
|
||||
s)
|
||||
song="true"
|
||||
if [[ "$(echo "$@" | grep -Eo "\-a")" == "-a" ]];then artist="true";fi # wont go through both options if arg spaced and not quoted this solves that issue (dont need this but once had bug on system where it was necessary)
|
||||
if [[ "$(echo "$@" | grep -Eo "\-f")" == "-f" ]];then filePath=$(echo "$@" | grep -Eo "\-f [ a-z A-Z / 0-9 . \ ]*[ -]?" | sed s/-f//g | sed s/-//g | sed s/^" "//g);fi
|
||||
;;
|
||||
:) echo "Option -$OPTARG requires an argument." >&2
|
||||
exit 1
|
||||
|
|
39
tests/lyrics.bats
Executable file
39
tests/lyrics.bats
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/env bats
|
||||
|
||||
@test "Testing lyrics tool" {
|
||||
echo lyrics
|
||||
}
|
||||
|
||||
@test "Check for latest version of bash-snippets on update" {
|
||||
if [[ "$(uname)" == "Linux" ]];then
|
||||
run lyrics update
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "Bash-Snippets is already the latest version" ]
|
||||
fi
|
||||
}
|
||||
|
||||
@test "The -h option should print usage" {
|
||||
run lyrics -h
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Lyrics" ]
|
||||
}
|
||||
|
||||
@test "No arguments prints usage instructions" {
|
||||
run lyrics
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Lyrics" ]
|
||||
}
|
||||
|
||||
@test "Getting some lyrics" {
|
||||
run lyrics -a logic -s run it
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${lines[0]}" = "Me and my team gotta intervene" ]
|
||||
}
|
||||
|
||||
@test "Getting some lyrics to file" {
|
||||
rm -f ~/templyrics.txt
|
||||
run lyrics -a logic -s run it -f ~/templyrics.txt
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat $HOME/templyrics.txt | grep -Eo "Me and my team gotta intervene")" = "Me and my team gotta intervene" ]
|
||||
rm -f ~/templyrics.txt
|
||||
}
|
Loading…
Reference in a new issue