diff --git a/compile.sh b/compile.sh old mode 100644 new mode 100755 index 15a0f61..79281ba --- a/compile.sh +++ b/compile.sh @@ -1,6 +1,19 @@ #!/bin/bash projectPattern="*.uvprojx"; +if [ "$#" -gt 1 ] +then + 1>&2 echo "Error: Invalid number of arguments: $#"; +fi; + +if [ "$#" -ne 1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] +then + echo "Usage: ${BASH_SOURCE[0]} "; + exit; +fi; + + + function handle_status() { if [ $1 -ne 0 ]; then echo "Error: $2 (status code: $1)"; @@ -153,6 +166,8 @@ function chooseTarget() { } fileName="$(realpath "$1")"; +test -f "$fileName"; +handle_status "$?" "The specified file \"$1\" does not exist!"; if [[ "$fileName" =~ \.uvprojx$ ]] then @@ -213,7 +228,7 @@ then then outputName="$(realpath "$projectRoot/$buildPath/$outputName")"; outputFile="$outputName.axf"; - echo "The File Has Been Built to \`$outputFile\`."; + echo "The File Has Been Built to \"$outputFile\"."; pyocd list | { grep '^No available' && { @@ -228,5 +243,5 @@ then handle_status 1 "The project could not be built!"; fi; else - handle_status 1 "No project file for \`${fileName}\` could be found." + handle_status 1 "No project file for \"${fileName}\" could be found." fi;