Added getopts

This commit is contained in:
2019-01-06 18:18:07 +01:00
parent d8ea6be7f2
commit 209300ef36

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# Specify a directory with all Git repositories
REPODIR=~/Git
REPODIR=$(pwd)
# Regex or fixed name (brackets need to be escaped with a backslash)
REPOUSER="\(structix\|Janek\)"
@@ -10,7 +10,7 @@ REPOUSER="\(structix\|Janek\)"
STARTDATE="01 Jan 2018"
# Verbose flag
VERBOSE=true
VERBOSE=false
# --------------------
# --- functions
@@ -107,5 +107,29 @@ function main() {
echo "Total deletions: $totaldeletions"
}
# process the arguments
print_usage() {
echo "$0 - git statistics over multiple directories"
echo ""
echo "options:"
echo "-h show this help page"
echo "-r <directory> set a directory with your repositories"
echo "-v show verbose output"
}
while getopts 'r:vh' flag; do
case "${flag}" in
r) REPODIR="${OPTARG}" ;;
v) VERBOSE=true ;;
h) print_usage; exit 0 ;;
*) print_usage
exit 1 ;;
esac
done
# Start the main function
main