mirror of
https://codeberg.org/kiss-community/kiss
synced 2024-09-28 12:22:39 -06:00
kiss: clean up argument handling
This commit is contained in:
parent
1e0c80493a
commit
6dde0696d8
62
kiss
62
kiss
@ -1373,41 +1373,45 @@ 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
|
||||||
[ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
|
a|alternatives|i|install|r|remove)
|
||||||
as_root HOME="$HOME" \
|
[ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
|
||||||
XDG_CACHE_HOME="$XDG_CACHE_HOME" \
|
as_root HOME="$HOME" \
|
||||||
KISS_PATH="$KISS_PATH" \
|
XDG_CACHE_HOME="$XDG_CACHE_HOME" \
|
||||||
KISS_FORCE="$KISS_FORCE" \
|
KISS_PATH="$KISS_PATH" \
|
||||||
KISS_ROOT="$KISS_ROOT" \
|
KISS_FORCE="$KISS_FORCE" \
|
||||||
KISS_CHOICE="$KISS_CHOICE" \
|
KISS_ROOT="$KISS_ROOT" \
|
||||||
KISS_COLOR="$KISS_COLOR" \
|
KISS_CHOICE="$KISS_CHOICE" \
|
||||||
KISS_TMPDIR="$KISS_TMPDIR" \
|
KISS_COLOR="$KISS_COLOR" \
|
||||||
KISS_PID="$KISS_PID" \
|
KISS_TMPDIR="$KISS_TMPDIR" \
|
||||||
"$0" "$action" "$@"
|
KISS_PID="$KISS_PID" \
|
||||||
|
"$0" "$action" "$@"
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user