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>2017-07-08 09:29:19 -0400
committerDave Reisner <dreisner@archlinux.org>2017-07-08 13:25:43 -0400
commit19dcc3111174284babb30742539bdef4fa8808c9 (patch)
tree74b1b13a2cf1d10a14ad18a21888e17138c05c28 /asp.in
parent8d504c6bb58f04ab0b600851ca0c22afc2245173 (diff)
avoid the need to maintain a separate list of actions
We have our nice action__ prefix on all of our action disspatchers, so let's just use that to our advantage. While we're here, fix the return code when we encounter an ambiguous action
Diffstat (limited to 'asp.in')
-rw-r--r--asp.in42
1 files changed, 13 insertions, 29 deletions
diff --git a/asp.in b/asp.in
index 418f8ea..e2dd60d 100644
--- a/asp.in
+++ b/asp.in
@@ -289,50 +289,34 @@ action__ls-files() {
}
dispatch_action() {
- local a candidates=()
- local actions=(
- checkout
- difflog
- disk-usage
- export
- gc
- help
- list-all
- list-arches
- list-local
- list-repos
- log
- ls-files
- shortlog
- show
- untrack
- update
- )
+ local candidates
[[ $1 ]] || log_fatal 'no action specified (use -h for help)'
- for a in "${actions[@]}"; do
- if [[ $a = "$1" ]]; then
- candidates=("$a")
- break
- fi
-
- [[ $a = "$1"* ]] && candidates+=("$a")
- done
+ # exact match
+ if declare -F "action__$1" &>/dev/null; then
+ "action__$@"
+ return
+ fi
+ # prefix match
+ mapfile -t candidates < <(compgen -A function "action__$1")
case ${#candidates[*]} in
0)
log_fatal 'unknown action: %s' "$1"
;;
1)
- "action__${candidates[0]}" "${@:2}"
+ "${candidates[0]}" "${@:2}"
+ return
;;
*)
{
printf "error: verb '%s' is ambiguous; possibilities:" "$1"
- printf " '%s'" "${candidates[@]}"
+ printf " '%s'" "${candidates[@]#action__}"
echo
} >&2
+ return 1
+ ;;
esac
}