Skip to content

Commit

Permalink
Merge pull request #17 from azohra/bugs/file-exist-check
Browse files Browse the repository at this point in the history
Added check on file flag for files that do not exist
  • Loading branch information
fvumbaca authored Feb 24, 2022
2 parents f6ebd00 + f25e8f3 commit 60e1e4a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ysh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ ysh() {
exit 0
;;
-f|--file)
if [ ! -f "${2}" ]; then
echo "Error: file ${2} does not exist" > /dev/stderr
exit 1
fi
YSH_RAW_STRING="$(YSH_parse "${2}")"
shift; shift
;;
Expand Down Expand Up @@ -154,7 +158,7 @@ ysh() {
exit 1
;;
*)
echo "Error: invalid use" > /dev/stdout
echo "Error: invalid use" > /dev/stderr
exit 1
;;
esac
Expand Down
Empty file modified test/shunit2
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,9 @@ testHelpFlagShouldNotBeAnError() {
assertEquals 0 $?
}

testFileDoesNotExist() {
result=$(ysh -f "does_not_exist.yaml" -s "doesnotmatter")
assertEquals 1 $?
}

. ./test/shunit2
6 changes: 5 additions & 1 deletion ysh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ ysh() {
exit 0
;;
-f|--file)
if [ ! -f "${2}" ]; then
echo "Error: file ${2} does not exist" > /dev/stderr
exit 1
fi
YSH_RAW_STRING="$(YSH_parse "${2}")"
shift; shift
;;
Expand Down Expand Up @@ -154,7 +158,7 @@ ysh() {
exit 1
;;
*)
echo "Error: invalid use" > /dev/stdout
echo "Error: invalid use" > /dev/stderr
exit 1
;;
esac
Expand Down

0 comments on commit 60e1e4a

Please sign in to comment.