From 5b8479552bce576d4e47f4a5794f710810bb97d0 Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Thu, 29 Jun 2017 12:21:28 -0400 Subject: [PATCH] Adding help to each tool --- crypt/crypt | 25 +++++++++++++++++++++++-- currency/currency | 17 +++++++++++++++-- movies/movies | 20 +++++++++++++++++--- stocks/stocks | 16 +++++++++++++--- weather/weather | 20 ++++++++++++++++++-- 5 files changed, 86 insertions(+), 12 deletions(-) diff --git a/crypt/crypt b/crypt/crypt index c915292..9d5409d 100755 --- a/crypt/crypt +++ b/crypt/crypt @@ -58,7 +58,19 @@ update() } -while getopts "uve:d:" opt; do ## alows for using options in bash + +usage() +{ + echo "Crypt tool" + echo "Usage: crypt [flag] [inputFile] [outputFile]" + echo " -e Encrypt the inputFile and store it in the outputFile" + echo " -d Decrypt the inputFile and store it in the outputFile" + echo " -u Update Bash-Snippet Tools" + echo " -h Show the help" + echo " -v Get the tool version" +} + +while getopts "huve:d:" opt; do ## alows for using options in bash case $opt in e) ## when trying to encrypt run this if [[ $# -ne 3 ]]; then @@ -82,6 +94,10 @@ while getopts "uve:d:" opt; do ## alows for using options in bash update exit 0 ;; + h) + usage + exit 0 + ;; v) echo "Version $currentVersion" exit 0 @@ -93,7 +109,12 @@ while getopts "uve:d:" opt; do ## alows for using options in bash esac done -if [[ $1 == "update" ]];then +if [[ $# == 0 ]]; then + usage +elif [[ $1 == "update" ]];then update exit 0 +elif [[ $1 == "help" ]];then + usage + exit 0 fi diff --git a/currency/currency b/currency/currency index 19d8d73..777adc0 100755 --- a/currency/currency +++ b/currency/currency @@ -174,16 +174,27 @@ update() } + +usage() +{ + echo "Currency tool" + echo "Usage: currency or currency [flag] or currency [base] [exchangeTo] [amount]" + echo " -u Update Bash-Snippet Tools" + echo " -h Show the help" + echo " -v Get the tool version" +} + checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here -while getopts "uv" opt; do +while getopts "uvh" opt; do case $opt in \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; h) - help + usage + exit 0 ;; v) echo "Version $currentVersion" @@ -209,6 +220,8 @@ if [[ $# == 0 ]]; then elif [[ $# == "1" ]]; then if [[ $1 == "update" ]];then update + elif [[ $1 == "help" ]]; then + usage else echo "Not a valid argument" fi diff --git a/movies/movies b/movies/movies index 61dce8c..1e66b8e 100755 --- a/movies/movies +++ b/movies/movies @@ -94,16 +94,26 @@ update() } +usage() +{ + echo "Movies tool" + echo "Usage: movies [flag] or movies [movieToSearch]" + echo " -u Update Bash-Snippet Tools" + echo " -h Show the help" + echo " -v Get the tool version" +} + checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here -while getopts "uv" opt; do +while getopts "uvh" opt; do case $opt in \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; h) - help + usage + exit 0 ;; v) echo "Version $currentVersion" @@ -120,8 +130,12 @@ while getopts "uv" opt; do esac done -if [[ $1 == "update" ]];then +if [[ $# == 0 ]]; then + usage +elif [[ $1 == "update" ]];then update +elif [[ $1 == "help" ]];then + usage else getMovieInfo $1 $2 $3 $4 $5 $6 $7 $8 $9 || exit 1 ## exit if we return 1 (chances are movie was not found) printMovieInfo ## print out the data diff --git a/stocks/stocks b/stocks/stocks index 2fb405c..6f22ccc 100755 --- a/stocks/stocks +++ b/stocks/stocks @@ -107,18 +107,26 @@ update() } +usage() +{ + echo "Stocks tool" + echo "Usage: stocks [flag or company]" + echo " -u Update Bash-Snippet Tools" + echo " -h Show the help" + echo " -v Get the tool version" +} checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here -while getopts "uv" opt; do +while getopts "uvh" opt; do case $opt in \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; h) - help + usage exit 0 ;; v) @@ -139,8 +147,10 @@ done if [[ $1 == "update" ]];then update +elif [[ $1 == "help" ]];then + usage elif [[ $# == "0" ]];then - echo "Error: requires an argument either stocks [company] or stocks [stock symbol]" + usage else getTicker $1 $2 $3 $4 $5 $6 $7 $8 $9 # the company name might have spaces so passing in all args allows for this getStockInformation $symbol # based on the stock symbol exrapolated by the getTicker function get information on the stock diff --git a/weather/weather b/weather/weather index 51affa0..a1066d2 100755 --- a/weather/weather +++ b/weather/weather @@ -75,19 +75,33 @@ update() } +usage() +{ + echo "Weather tool" + echo "Usage: weather or weather [flag] or weather [country] or weather [city] [state]" + echo " weather [i] get weather in imperial units" + echo " weather [m] get weather in metric units" + echo " weather [Moon] grabs the phase of the moon" + echo " -u Update Bash-Snippet Tools" + echo " -h Show the help" + echo " -v Get the tool version" +} + + checkInternet || exit 1 # check if we have a valid internet connection if this isnt true the rest of the script will not work so stop here -while getopts "uv" opt; do +while getopts "uvh" opt; do case $opt in \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; h) - help + usage + exit 0 ;; v) echo "Version $currentVersion" @@ -106,6 +120,8 @@ done if [[ $# == "0" ]]; then getIPWeather +elif [[ $1 == "help" ]];then + usage elif [[ $1 == "update" ]]; then update elif [[ $1 == "m" ]]; then