diff options
| author | Mike Frysinger <vapier@google.com> | 2021-07-26 15:26:22 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-07-27 06:20:52 +0000 |
| commit | b380322174c9b67da99ce743ff49382bab5cf351 (patch) | |
| tree | faafad6f1dee5bc8af572d4434976fa8be43e37f | |
| parent | 13d6c94cfb4783a8b92dd26c7a9b3de134d8c018 (diff) | |
| download | git-repo-b380322174c9b67da99ce743ff49382bab5cf351.tar.gz | |
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>
| -rw-r--r-- | completion.bash | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/completion.bash b/completion.bash index 3c1fd683..04347ce3 100644 --- a/completion.bash +++ b/completion.bash | |||
| @@ -66,6 +66,31 @@ __complete_repo_command_projects() { | |||
| 66 | COMPREPLY=($(compgen -W "$(__complete_repo_list_projects)" -- "${current}")) | 66 | COMPREPLY=($(compgen -W "$(__complete_repo_list_projects)" -- "${current}")) |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | # Complete `repo help`. | ||
| 70 | __complete_repo_command_help() { | ||
| 71 | local current=$1 | ||
| 72 | # CWORD=1 is "start". | ||
| 73 | # CWORD=2 is the <subcommand> which we complete here. | ||
| 74 | if [[ ${COMP_CWORD} -eq 2 ]]; then | ||
| 75 | COMPREPLY=( | ||
| 76 | $(compgen -W "$(__complete_repo_list_commands)" -- "${current}") | ||
| 77 | ) | ||
| 78 | fi | ||
| 79 | } | ||
| 80 | |||
| 81 | # Complete `repo start`. | ||
| 82 | __complete_repo_command_start() { | ||
| 83 | local current=$1 | ||
| 84 | # CWORD=1 is "start". | ||
| 85 | # CWORD=2 is the <branch> which we don't complete. | ||
| 86 | # CWORD=3+ are <projects> which we complete here. | ||
| 87 | if [[ ${COMP_CWORD} -gt 2 ]]; then | ||
| 88 | COMPREPLY=( | ||
| 89 | $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") | ||
| 90 | ) | ||
| 91 | fi | ||
| 92 | } | ||
| 93 | |||
| 69 | # Complete the repo subcommand arguments. | 94 | # Complete the repo subcommand arguments. |
| 70 | __complete_repo_arg() { | 95 | __complete_repo_arg() { |
| 71 | if [[ ${COMP_CWORD} -le 1 ]]; then | 96 | if [[ ${COMP_CWORD} -le 1 ]]; then |
| @@ -86,21 +111,8 @@ __complete_repo_arg() { | |||
| 86 | return 0 | 111 | return 0 |
| 87 | ;; | 112 | ;; |
| 88 | 113 | ||
| 89 | help) | 114 | help|start) |
| 90 | if [[ ${COMP_CWORD} -eq 2 ]]; then | 115 | __complete_repo_command_${command} "${current}" |
| 91 | COMPREPLY=( | ||
| 92 | $(compgen -W "$(__complete_repo_list_commands)" -- "${current}") | ||
| 93 | ) | ||
| 94 | fi | ||
| 95 | return 0 | ||
| 96 | ;; | ||
| 97 | |||
| 98 | start) | ||
| 99 | if [[ ${COMP_CWORD} -gt 2 ]]; then | ||
| 100 | COMPREPLY=( | ||
| 101 | $(compgen -W "$(__complete_repo_list_projects)" -- "${current}") | ||
| 102 | ) | ||
| 103 | fi | ||
| 104 | return 0 | 116 | return 0 |
| 105 | ;; | 117 | ;; |
| 106 | 118 | ||
