Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/asp.in
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2016-06-18 10:41:44 -0400
committerDave Reisner <dreisner@archlinux.org>2016-06-18 10:41:44 -0400
commit0e1f29ddf377044eb47333dfb35f090c4f32779d (patch)
tree07a0ab74b3dab2dd382081e96fe2d8563aff8da3 /asp.in
parente7e01df2b04b07e9f6c8065cc67fea5f7c9135f5 (diff)
add argc checks for commands
Diffstat (limited to 'asp.in')
-rw-r--r--asp.in33
1 files changed, 33 insertions, 0 deletions
diff --git a/asp.in b/asp.in
index 187416a..49e614a 100644
--- a/asp.in
+++ b/asp.in
@@ -42,6 +42,25 @@ Commands:
EOF
}
+__require_argc() {
+ local operator=$1 expected=$2 got=$(( ${#BASH_ARGV[@]} - 1 ))
+
+ case $operator in
+ '==')
+ (( got == expected )) ||
+ log_fatal '%s expects %d args, got %d' "${FUNCNAME[1]#action__}" "$expected" "$got"
+ ;;
+ '>=')
+ (( got >= expected )) ||
+ log_fatal '%s expects at least %d args, got %d' "${FUNCNAME[1]#action__}" "$expected" "$got"
+ ;;
+ '<=')
+ (( got <= expected )) ||
+ log_fatal '%s expects at most %d args, got %d' "${FUNCNAME[1]#action__}" "$expected" "$got"
+ ;;
+ esac
+}
+
version() {
printf 'asp v0\n'
}
@@ -172,58 +191,72 @@ disk_usage() {
}
action__checkout() {
+ __require_argc '>=' 1
map package_checkout "$@"
}
action__difflog() {
+ __require_argc == 1
difflog "$1"
}
action__disk-usage() {
+ __require_argc == 0
disk_usage
}
action__export() {
+ __require_argc '>=' 1
map package_export "$@"
}
action__gc() {
+ __require_argc == 0
gc
}
action__help() {
+ __require_argc == 0
usage
}
action__list-all() {
+ __require_argc == 0
list_all
}
action__list-arches() {
+ __require_argc '>=' 1
map package_get_arches "$@"
}
action__list-local() {
+ __require_argc == 0
list_local
}
action__list-repos() {
+ __require_argc '>=' 1
map package_get_repos "$@"
}
action__log() {
+ __require_argc == 1
log "$1"
}
action__shortlog() {
+ __require_argc == 1
shortlog "$1"
}
action__show() {
+ __require_argc == 1
package_show_pkgbuild "$1"
}
action__untrack() {
+ __require_argc '>=' 1
map untrack "$@"
}