summaryrefslogtreecommitdiff
path: root/completion.bash
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-07-26 15:26:22 -0400
committerMike Frysinger <vapier@google.com>2021-07-27 06:20:52 +0000
commitb380322174c9b67da99ce743ff49382bab5cf351 (patch)
treefaafad6f1dee5bc8af572d4434976fa8be43e37f /completion.bash
parent13d6c94cfb4783a8b92dd26c7a9b3de134d8c018 (diff)
downloadgit-repo-b380322174c9b67da99ce743ff49382bab5cf351.tar.gz
git-repo-b380322174c9b67da99ce743ff49382bab5cf351.zip
bash-completion: refactor unique subcommand processing
Let's keep the main processing loop free of subcommand implementations by pulling the existing help & start commands into dedicated functions. Having a single giant function is harder to track as we add more and more logic in. Bug: https://crbug.com/gerrit/14797 Change-Id: I2b62dc430c0e7574f09aa4838f4ef03fbe4bf7fb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312903 Reviewed-by: Xin Li <delphij@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'completion.bash')
-rw-r--r--completion.bash42
1 files changed, 27 insertions, 15 deletions
diff --git a/completion.bash b/completion.bash
index 3c1fd683b..04347ce3f 100644
--- a/completion.bash
+++ b/completion.bash
@@ -66,6 +66,31 @@ __complete_repo_command_projects() {
COMPREPLY=($(compgen -W "$(__complete_repo_list_projects)" -- "${current}"))
}
+# Complete `repo help`.
+__complete_repo_command_help() {
+ local current=$1
+ # CWORD=1 is "start".
+ # CWORD=2 is the <subcommand> which we complete here.
+ if [[ ${COMP_CWORD} -eq 2 ]]; then
+ COMPREPLY=(
+ $(compgen -W "$(__complete_repo_list_commands)" -- "${current}")
+ )
+ fi
+}
+
+# Complete `repo start`.
+__complete_repo_command_start() {
+ local current=$1
+ # CWORD=1 is "start".
+ # CWORD=2 is the <branch> which we don't complete.
+ # CWORD=3+ are <projects> which we complete here.
+ if [[ ${COMP_CWORD} -gt 2 ]]; then
+ COMPREPLY=(
+ $(compgen -W "$(__complete_repo_list_projects)" -- "${current}")
+ )
+ fi
+}
+
# Complete the repo subcommand arguments.
__complete_repo_arg() {
if [[ ${COMP_CWORD} -le 1 ]]; then
@@ -86,21 +111,8 @@ __complete_repo_arg() {
return 0
;;
- help)
- if [[ ${COMP_CWORD} -eq 2 ]]; then
- COMPREPLY=(
- $(compgen -W "$(__complete_repo_list_commands)" -- "${current}")
- )
- fi
- return 0
- ;;
-
- start)
- if [[ ${COMP_CWORD} -gt 2 ]]; then
- COMPREPLY=(
- $(compgen -W "$(__complete_repo_list_projects)" -- "${current}")
- )
- fi
+ help|start)
+ __complete_repo_command_${command} "${current}"
return 0
;;