Support spaces in files name

This commit is contained in:
Maniack Crudelis 2017-11-11 00:46:22 +01:00
parent ce12c1b4b5
commit eee83b8500

View file

@ -57,69 +57,87 @@ then
# Print the help and exit # Print the help and exit
notice=1 notice=1
else else
# Reduce the arguments for getopts # Store arguments in a array to keep each argument separated
arguments="$*" arguments=("$@")
arguments=${arguments//--branch=/-b}
arguments=${arguments//--force-install-ok/-f} # Read the array value per value
arguments=${arguments//--interrupt/-i} for i in `seq 0 $(( ${#arguments[@]} -1 ))`
arguments=${arguments//--help/-h} do
arguments=${arguments//--build-lxc/-l} # For each argument in the array, reduce to short argument for getopts
arguments=${arguments//--bash-mode/-y} arguments[$i]=${arguments[$i]//--branch=/-b}
arguments[$i]=${arguments[$i]//--force-install-ok/-f}
arguments[$i]=${arguments[$i]//--interrupt/-i}
arguments[$i]=${arguments[$i]//--help/-h}
arguments[$i]=${arguments[$i]//--build-lxc/-l}
arguments[$i]=${arguments[$i]//--bash-mode/-y}
done
# Read and parse all the arguments # Read and parse all the arguments
# Use a function here, to use standart arguments $@ and use more simply getopts and shift. # Use a function here, to use standart arguments $@ and be able to use shift.
parse_arg () { parse_arg () {
while [ $# -ne 0 ] while [ $# -ne 0 ]
do do
# Initialize the index of getopts # If the paramater begins by -, treat it with getopts
OPTIND=1 if [ "${1:0:1}" == "-" ]
# Parse with getopts only if the argument begin by -
if [ ${1:0:1} = "-" ]
then then
getopts ":b:fihly " parameter # Initialize the index of getopts
OPTIND=1
# Parse with getopts only if the argument begin by -
getopts ":b:fihly" parameter || true
case $parameter in case $parameter in
b) b)
# --branch=branch-name # --branch=branch-name
gitbranch="-b $OPTARG" gitbranch="-b $OPTARG"
shift_value=2
;; ;;
f) f)
# --force-install-ok # --force-install-ok
force_install_ok=1 force_install_ok=1
shift_value=1
;; ;;
i) i)
# --interrupt # --interrupt
interrupt=1 interrupt=1
shift_value=1
;; ;;
h) h)
# --help # --help
notice=1 notice=1
shift_value=1
;; ;;
l) l)
# --build-lxc # --build-lxc
build_lxc=1 build_lxc=1
shift_value=1
;; ;;
y) y)
# --bash-mode # --bash-mode
bash_mode=1 bash_mode=1
shift_value=1
;; ;;
\?) \?)
echo "Invalid argument: -$OPTARG" >&2 echo "Invalid argument: -${OPTARG:-}"
notice=1 notice=1
shift_value=1
;; ;;
:) :)
echo "-$OPTARG parameter requires an argument." >&2 echo "-$OPTARG parameter requires an argument."
notice=1 notice=1
shift_value=1
;; ;;
esac esac
# Otherwise, it's not an option, it's an operand
else else
app_arg="$1" app_arg="$1"
shift_value=1
fi fi
shift # Shift the parameter and its argument
shift $shift_value
done done
} }
# Call parse_arg and pass the modified list of args. # Call parse_arg and pass the modified list of args as a array of arguments.
parse_arg $arguments parse_arg "${arguments[@]}"
fi fi
# Prevent a conflict between --interrupt and --bash-mode # Prevent a conflict between --interrupt and --bash-mode