aboutsummaryrefslogtreecommitdiff
blob: d9bfdf2f141d05824397660572c3cd7ac87b1e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# R overlay -- bash completion for roverlay
# -*- coding: utf-8 -*-

_roverlay_comp() {
   local cur
   local prev

   COMPREPLY=()
   _get_comp_words_by_ref cur prev

   local LONGOPTS=(
      '--help' '--version'
      '--config' '--field-definition' '--fdef' '--repo-config'
      '--deprule-file' '--package-rules' '--overlay' '--overlay-name'
      '--additions-dir'
      '--write-overlay' '--write' '--no-write-overlay' '--no-write'
      '--show-overlay' '--show' '--no-show-overlay' '--no-show'
      '--strict-sync' '--sync' '--no-sync' '--sync-imports'
      '--distroot' '--force-distroot' '--local-distdir' '--from'
      '--incremental' '--no-incremental' '--fixup-category-move'
      '--fixup-category-move-reverse' '--distmap-verify' '--revbump'
      '--no-revbump' '--immediate-ebuild-writes' '--manifest' '--no-manifest'
      '--manifest-implementation' '--pc' '--print-config'
      '--ppr' '--print-package-rules'
      '--help-config' '--list-config-entries' '--dump-file' '--strict'
      '--stats' '--no-stats' '--dump-stats'
      '--log-level' '--verbose'
   )

   local SHORTOPTS=(
      '-h' '-V' '-c' '-F' '-R' '-D' '-P' '-O' '-N' '-A' '-M' '-v'
   )

   local CMDARGS=(
      'sync' 'create' 'depres' 'depres_console' 'nop' 'apply_rules'
      'setupdirs' 'distmap_rebuild'
   )

   local have_command=
   local k
   local first=y
   for k in "${COMP_WORDS[@]}"; do
      if [[ " ${CMDARGS[*]} " == *" ${k} "* ]] && [[ -z "${first}" ]]; then
         have_command=y
         break
      fi
      first=
   done

   case "${prev}" in
      '-c'|'--config'|'-F'|'--field-definition'|'--fdef'|\
      '-R'|'--repo-config')
         # options with <file> arg
         _filedir
      ;;

      '-O'|'--overlay'|'-A'|'--additions-dir'|'--distroot'|\
      '--local-distdir'|'--from')
      # options with <dir> arg
         _filedir -d
      ;;

      '-D'|'--deprule-file'|'-P'|'--package-rules')
         # options with <file|dir> arg
         _filedir
      ;;

      '--dump-file')
         # stdout or file
         _filedir
         [[ "${cur}" ]] || COMPREPLY+=( "-" )
      ;;

      '-M'|'--manifest-implementation')
         COMPREPLY=( $(compgen -W "default next ebuild e" -- "${cur}" ) )
      ;;

      '-N'|'--overlay-name')
         # options with str/unspecified arg
         true
      ;;

      '--log-level')
         COMPREPLY=(
            $(compgen -W "DEBUG INFO WARN WARNING ERROR CRITICAL" -- "${cur}" )
         )
      ;;

      *)
         case "${cur}" in
            --*)
               COMPREPLY=( $( compgen -W "${LONGOPTS[*]}" -- "${cur}" ) )
            ;;
            -*)
               COMPREPLY=(
                  $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" )
               )
            ;;
            *)
               local words="${LONGOPTS[*]} ${SHORTOPTS[*]}"
               [[ "${have_command}" ]] || words+=" ${CMDARGS[*]}"
               COMPREPLY=( $( compgen -W "${words}" -- "${cur}" ) )
            ;;
         esac

      ;;
   esac
}
complete -F _roverlay_comp roverlay

_roverlay_status_comp() {
   local cur
   local prev

   COMPREPLY=()
   _get_comp_words_by_ref cur prev

   local MODE_LONGOPTS=( '--mode' '--cli' '--html' '--cgi' )
   local LONGOPTS=(
      '--help' '--version'
      '--config'
      '--output' '--template' '--cgi-content-type' '--module-root'
   )

   local MODE_SHORTOPTS=( '-m' )
   local SHORTOPTS=(
      '-h' '-V' '-c' '-O' '-t' '-T' '-M'
   )

   local CMDARGS=( 'status' )

   local have_mode=
   local have_command=
   local k
   local first=y
   for k in "${COMP_WORDS[@]}"; do
      if [[ -z "${first}" ]]; then
         case "${k}" in
            '--cgi'|'--cli'|'--html'|'--mode'|'-m')
               have_mode=y
            ;;
            *)
               if [[ " ${CMDARGS[*]} " == *" ${k} "* ]]; then
                  have_command=y
               fi
            ;;
         esac

         if [[ ( "${have_mode}" ) && ( "${have_command}" ) ]]; then
            break
         fi
      else
         first=
      fi
   done

   if [[ -z "${have_mode}" ]]; then
      LONGOPTS+=( "${MODE_LONGOPTS[@]}" )
      SHORTOPTS+=( "${MODE_SHORTOPTS[@]}" )
   fi

   case "${prev}" in
      '-c'|'--config'|'-O'|'--output')
         # options with <file> arg
         _filedir
      ;;

      '-t'|'--template')
         # --template accepts names and files
         _filedir
      ;;

      '-M'|'--module-root')
      # options with <dir> arg
         _filedir -d
      ;;

      '-m'|'--mode')
         COMPREPLY=( $(compgen -W "cli html cgi" -- "${cur}" ) )
      ;;

      '-T'|'--cgi-content-type')
         # accepts any word, but text/plain, text/html are common choices
         COMPREPLY=( $(compgen -W "text/plain text/html" -- "${cur}" ) )
      ;;

      *)
         case "${cur}" in
            --*)
               COMPREPLY=( $( compgen -W "${LONGOPTS[*]}" -- "${cur}" ) )
            ;;
            -*)
               COMPREPLY=(
                  $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" )
               )
            ;;
            *)
               local words="${LONGOPTS[*]} ${SHORTOPTS[*]}"
               [[ "${have_command}" ]] || words+=" ${CMDARGS[*]}"
               COMPREPLY=( $( compgen -W "${words}" -- "${cur}" ) )
            ;;
         esac

      ;;
   esac
}
complete -F _roverlay_status_comp roverlay-status

_roverlay_setup_comp() {
   local cur
   local prev

   COMPREPLY=()
   _get_comp_words_by_ref cur prev

   local LONGOPTS=(
      '--help' '--usage' '--version'
      '--work-root' '--data-root' '--conf-root' '--conf-dir' '--my-conf-root'
      '--target-type' '--foreign' '--not-gentoo'
      '--output' '--ask' '--expand-user' '--additions-dir' '--variable'
      '--prjroot-relpath' '--enable-default-hooks' '--no-default-hooks'
      '--import-config' '--no-import-config' '--force-import-config'
      '--target-uid' '--target-gid'
      '--overwrite-hooks' '--relpath-hooks' '--no-relpath-hooks'
   )
   local SHORTOPTS=(
      '-h' '-V' '-W' '-D' '-C' '-O' '-a' '-A' '-v' '-I'
   )

   local CMDARGS=( 'init' 'hooks' 'mkconfig' )

   local CONFIG_IMPORT_MODES=(
      'disable' 'symlink' 'symlink=root' 'symlink=dirs' 'symlink=files copy'
   )
   local HOOK_OVERWRITE=( 'none' 'dead' 'links' 'all' )

   local have_command
   local k
   local first=y
   for k in "${COMP_WORDS[@]}"; do
      if [[ " ${CMDARGS[*]} " == *" ${k} "* ]] && [[ -z "${first}" ]]; then
         have_command="${k}"
         case "${k}" in
            'init'|'hooks')
               LONGOPTS+=( '--pretend' )
               SHORTOPTS+=( '-p' )
            ;;
         esac
         break
      else
         first=
      fi
   done

   # bashcomp for subcommands is missing:
   # * init, mkconfig do not have any special options
   # * hooks has "show|add|del <hook> <event>..."
   [[ -z "${have_command-}" ]] || return 0

   case "${prev}" in
      '-v'|'--variable')
         :
      ;;

      '-W'|'--work-root'|'-D'|'--data-root'|'--conf-root'|\
      '-C'|'--conf-dir'|'--my-conf-root'|'-A'|'--additions-dir')
         # options with <dir> arg
         _filedir -d
      ;;

      '-O'|'--output')
         # <dir>|<file>|-
         _filedir
         [[ "${cur}" ]] || COMPREPLY+=( "-" )
      ;;

      '-I'|'--import-config')
         COMPREPLY=( $(compgen -W "${CONFIG_IMPORT_MODES[*]}" -- "${cur}" ) )
      ;;

      '--overwrite-hooks')
         COMPREPLY=( $(compgen -W "${HOOK_OVERWRITE[*]}" -- "${cur}" ) )
      ;;

      '--target-uid')
         COMPREPLY=( $( compgen -u -- "${cur}" ) )
         #_uids
         #COMPREPLY+=
      ;;

      '--target-gid')
         COMPREPLY=( $( compgen -g -- "${cur}" ) )
         #_gids
         #COMPREPLY+=
      ;;

      '--target-type')
         COMPREPLY=( $( compgen -W "gentoo foreign" -- "${cur}" ) )
      ;;

      *)
         case "${cur}" in
            --*)
               COMPREPLY=( $( compgen -W "${LONGOPTS[*]}" -- "${cur}" ) )
            ;;
            -*)
               COMPREPLY=(
                  $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" )
               )
            ;;
            *)
               local words="${LONGOPTS[*]} ${SHORTOPTS[*]}"
               [[ "${have_command}" ]] || words+=" ${CMDARGS[*]}"
               COMPREPLY=( $( compgen -W "${words}" -- "${cur}" ) )
            ;;
         esac
      ;;
   esac
}
complete -F _roverlay_setup_comp roverlay-setup

_roverlay_query_config_comp() {
   local cur
   local prev

   COMPREPLY=()
   _get_comp_words_by_ref cur prev

   local LONGOPTS=(
      '--help' '--config-file' '--all' '--list-all'
      '--empty-missing' '--from-file' '--outfile' '--variable'
   )
   local SHORTOPTS=(
      '-h' '-c' '-a' '-l' '-u' '-f' '-O' '-v'
   )

   case "${prev}" in
      '-c'|'--config-file'|'-f'|'--from-file'|'-O'|'--outfile')
         # <file> arg
         _filedir
      ;;
      '-v'|'--variable')
         true
      ;;
      *)
         COMPREPLY=(
            $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" )
         )
      ;;
   esac
}
complete -F _roverlay_query_config_comp roverlay-query-config