From 846472f0eb77841b8a9be52a897458b602b6dae7 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 30 Oct 2013 20:37:21 -0400 Subject: librechroot: check argument counts --- src/chroot-tools/librechroot | 48 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index ccd8273..b55cae1 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -21,10 +21,11 @@ set -euE # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . -# HACKING: if a command is added or removed, it must be changed in 3 places: +# HACKING: if a command is added or removed, it must be changed in 4 places: # - the usage() text # - the commands=() array -# - the case statement in main() +# - the case statement in main() that checks the number of arguments +# - the case statement in main() that runs them . $(librelib conf) load_files chroot @@ -238,6 +239,49 @@ main() { return 1 fi shift + case "$mode" in + noop|make|sync|delete|update|enter|clean-pkgs|clean-repo) + if [[ $# -gt 0 ]]; then + error 'Command `%s` does not take any arguments: %s' "$mode" "$*" + usage >/dev/stderr + return 1 + fi + :;; + install-file) + if [[ $# -lt 1 ]]; then + error 'Command `%s` requires at least one file' "$mode" + usage >/dev/stderr + return 1 + else + local missing=() + local file + for file in "$@"; do + if ! [[ -f $file ]]; then + missing+=("$file") + fi + done + if [[ ${#missing[@]} -gt 0 ]]; then + error "%s: file(s) not found: %s" "$mode" "${missing[*]}" + return 1 + fi + fi + :;; + install-name) + if [[ $# -lt 1 ]]; then + error 'Command `%s` requires at least one package name' "$mode" + usage >/dev/stderr + return 1 + fi + :;; + run) + if [[ $# -lt 1 ]]; then + error 'Command `%s` requires at least one argument' "$mode" + usage >/dev/stderr + return 1 + fi + :;; + esac + if [[ $mode == help ]]; then usage -- cgit v1.2.2