xref: /aosp_15_r20/external/pigweed/pw_cli/py/pw_cli/shell_completion/pw_build.bash (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2023 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15# Source common bash completion functions
16# Path to this directory, works in bash and zsh
17
18__pw_complete_recipes () {
19  local cur="${COMP_WORDS[COMP_CWORD]}"
20  local all_recipes=$(pw --no-banner build --tab-complete-recipe "${cur}")
21  COMPREPLY=($(compgen -W "$all_recipes" -- "$cur"))
22}
23
24__pw_complete_presubmit_steps () {
25  local cur="${COMP_WORDS[COMP_CWORD]}"
26  local all_recipes=$(pw --no-banner build --tab-complete-presubmit-step "${cur}")
27  COMPREPLY=($(compgen -W "$all_recipes" -- "$cur"))
28}
29
30_pw_build () {
31  local cur="${COMP_WORDS[COMP_CWORD]}"
32  local prev="${COMP_WORDS[COMP_CWORD-1]}"
33
34  case "$prev" in
35  -r|--recipe)
36    __pw_complete_recipes
37    return
38    ;;
39  -s|--step)
40    __pw_complete_presubmit_steps
41    return
42    ;;
43  --logfile)
44    # Complete a file
45    COMPREPLY=($(compgen -f "$cur"))
46    return
47    ;;
48  *)
49    ;;
50  esac
51
52  case "$cur" in
53  -*)
54    __pwcomp
55    local all_options=$(pw --no-banner build --tab-complete-option "")
56    __pwcomp "${all_options}"
57    return
58    ;;
59  esac
60  # Non-option args go here
61  COMPREPLY=()
62}
63