unify argument parsing

This commit is contained in:
Dylan Araps 2021-07-06 20:41:25 +03:00
parent fe6c391b10
commit c3fa50a921
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C
1 changed files with 15 additions and 17 deletions

32
kiss
View File

@ -1516,25 +1516,23 @@ args() {
esac
;;
b|build|c|checksum|d|download|l|list|r|remove)
case $* in */*|*\**|*\!*|*\[*|*\]*)
die "Arguments contain invalid characters: '/!*[]' ($*)"
b|build|c|checksum|d|download|i|install|l|list|r|remove)
case ${action%%"${action#?}"}-$* in
i-*[\*\!\[\]]*)
die "Arguments contain invalid characters: '!*[]' ($*)"
;;
[!i]-*[\*\!\[\]/]*)
die "Arguments contain invalid characters: '!*[]/' ($*)"
;;
[!l]-)
# Use basename of current directory as package.
export KISS_PATH=${PWD%/*}:$KISS_PATH
set -- "${PWD##*/}"
;;
esac
;;
i|install)
case $* in *\**|*\!*|*\[*|*\]*)
die "Arguments contain invalid characters: '!*[]' ($*)"
esac
;;
esac
# CRUX style usage using the current directory as the name of the package
# to be operated on. This needs to sit before the 'as_root()' calls as
# they reset the current working directory during their invocations.
[ "$1" ] || case $action in b|build|c|checksum|d|download|i|install|r|remove)
export KISS_PATH=${PWD%/*}:$KISS_PATH
set -- "${PWD##*/}"
esac
# Rerun the script as root with a fixed environment if needed. We sadly