Rework argument parsing to support position-independent arguments
This commit is contained in:
parent
56fb8bfa50
commit
3086d9a5c5
18
ptgdp
18
ptgdp
@ -320,7 +320,10 @@ playlist() {
|
|||||||
|
|
||||||
# Main
|
# Main
|
||||||
main() {
|
main() {
|
||||||
# Getopts before anything else
|
# Parse out arguments
|
||||||
|
# Done in a nested loop so that flags are position-independent
|
||||||
|
while [ -n "$1" ]; do
|
||||||
|
# Parse out flags
|
||||||
while getopts ":c:dhmpv" opt; do
|
while getopts ":c:dhmpv" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
c)
|
c)
|
||||||
@ -349,6 +352,14 @@ main() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
# Store arguments
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
_args+=("$1")
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
unset OPTIND
|
||||||
|
done
|
||||||
# Early hook for help
|
# Early hook for help
|
||||||
[ -n "$_opthelp" ] && printhelp && exit 0
|
[ -n "$_opthelp" ] && printhelp && exit 0
|
||||||
# Parse out a config file if it exists
|
# Parse out a config file if it exists
|
||||||
@ -366,11 +377,6 @@ main() {
|
|||||||
else
|
else
|
||||||
warn "Could not find configuration file" 2
|
warn "Could not find configuration file" 2
|
||||||
fi
|
fi
|
||||||
# Store arguments
|
|
||||||
shift $((OPTIND - 1))
|
|
||||||
for arg in "$@"; do
|
|
||||||
_args+=("$arg")
|
|
||||||
done
|
|
||||||
# Validate critical options
|
# Validate critical options
|
||||||
if [ -z "$_optmachinemode" ]; then
|
if [ -z "$_optmachinemode" ]; then
|
||||||
# Ensure we have a good backend, assuming we're not in a scripting mode
|
# Ensure we have a good backend, assuming we're not in a scripting mode
|
||||||
|
Loading…
Reference in New Issue
Block a user