Browse Source

Added option parsing

Matteo Zeccoli Marazzini 5 years ago
parent
commit
d79adf4850
2 changed files with 17 additions and 3 deletions
  1. 2 1
      newdisk-automator.sh
  2. 15 2
      parse-arguments.sh

+ 2 - 1
newdisk-automator.sh

@@ -7,13 +7,14 @@ DIR="/home/ravioli/newdisk-automator"
 
 PROGRAM_NAME="$0"
 
+parse_arguments $@
+
 DEVICE=$1
 SWAP_SIZE=$2
 CONDOR_SIZE=$3
 TEMP_SIZE=$4
 VM_SIZE=$5
 
-fatal 2
 
 # checking if the disk is used
 if [ ! -e ${DEVICE} ] ; then

+ 15 - 2
parse-arguments.sh

@@ -1,6 +1,19 @@
 parse_arguments()
 {
-	if [ $# -lt 1 ] || [ $# -gt 5 ]; then
-		fatal EUSAGE
+	while getopts ":fh" o; do
+		case $o in
+		f) FORCE=1;;
+		h) help && exit 0;;
+		\?) usage && exit;;
+		esac
+	done
+	shift `expr $OPTIND - 1`
+	
+	if [ $# -eq 1 ]; then
+		default
+	elif [ $# -eq 5 ] && [ $FORCE -ne 1 ]; then
+		manual
+	else
+		usage && exit
 	fi
 }