kiss: clean up argument handling

This commit is contained in:
Dylan Araps 2020-09-14 12:22:25 +03:00
parent 1e0c80493a
commit 6dde0696d8
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 33 additions and 29 deletions

30
kiss
View File

@ -1373,27 +1373,30 @@ args() {
action=$1 action=$1
shift "$(($# != 0))" shift "$(($# != 0))"
# Unless this is a search, sanitize the user's input. The call to case $action in
# 'pkg_find()' supports basic globbing, ensure input doesn't expand b|build|c|checksum|d|download|i|install|r|remove)
# to anything except for when this behavior is needed. # This handles the globbing characters '*', '!', '[' and ']' and
# # basic white-space. Invalid input characters in other words.
# This handles the globbing characters '*', '!', '[' and ']' as per: case "$*" in
# https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html *'*'*|*'!'*|*'['*|*']'*|*' '*|*' '*)
[ "${action##[as]*}" ] && case "$*" in *\**|*\!*|*\[*|*\]*) die "Arguments contain invalid characters: '!*[ \t]'"
die "Arguments contain invalid characters: '!*[]' ($*)" ;;
esac esac
# CRUX style usage using the current directory as the name of the package # CRUX style usage using the current directory as the name of the
# to be operated on. This needs to sit before the 'as_root()' calls as # package to be operated on. This needs to sit before the 'as_root()'
# they reset the current working directory during their invocations. # calls as they reset the cwd during their invocations.
[ "$1" ] || case $action in b|build|c|checksum|d|download|i|install|r|remove) [ "$1" ] || {
export KISS_PATH=${PWD%/*}:$KISS_PATH export KISS_PATH=${PWD%/*}:$KISS_PATH
set -- "${PWD##*/}" set -- "${PWD##*/}"
}
;;
esac esac
# Rerun the script as root with a fixed environment if needed. We sadly # Rerun the script as root with a fixed environment if needed. We sadly
# can't run singular functions as root so this is needed. # can't run singular functions as root so this is needed.
case $action in a|alternatives|i|install|r|remove) case $action in
a|alternatives|i|install|r|remove)
[ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || { [ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
as_root HOME="$HOME" \ as_root HOME="$HOME" \
XDG_CACHE_HOME="$XDG_CACHE_HOME" \ XDG_CACHE_HOME="$XDG_CACHE_HOME" \
@ -1408,6 +1411,7 @@ args() {
return return
} }
;;
esac esac
# Actions can be abbreviated to their first letter. This saves keystrokes # Actions can be abbreviated to their first letter. This saves keystrokes