summaryrefslogtreecommitdiff
path: root/src/chroot-tools/librechroot
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-10-30 20:37:21 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-10-30 20:37:21 -0400
commit846472f0eb77841b8a9be52a897458b602b6dae7 (patch)
tree6889877f14cc0633df0243593f3c895c7c7828b8 /src/chroot-tools/librechroot
parent11ca293c188ad394e2383381a4bce152cc7f0723 (diff)
librechroot: check argument counts
Diffstat (limited to 'src/chroot-tools/librechroot')
-rwxr-xr-xsrc/chroot-tools/librechroot48
1 files changed, 46 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>.
-# 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