Skip to content

Commit 27cd492

Browse files
committed
docs(api-and-naming: clarify modifications to target variable
1 parent 6f9e3a2 commit 27cd492

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

doc/api-and-naming.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ specified by `-v var` in `OPTS`).
145145
### Implementing a generator function
146146

147147
To implement a generator function, one should generate completion candidates by
148-
calling `_comp_compgen` or other generators. One should not directly modify or
148+
calling `_comp_compgen` or other generators. To avoid conflicts with the
149+
options specified to `_comp_compgen`, one should not directly modify or
149150
reference the target variable. When post-filtering is needed, store them in
150151
local arrays, filter them, and finally append them by `_comp_compgen -- -W
151152
"${arr[@]}"`.
@@ -166,9 +167,11 @@ The exit status is implementation-defined.
166167
`_comp_compgen_help || _comp_compgen_usage`.
167168

168169
Whether to clear the target variable on runtime error (when `-a` is not
169-
specified in `OPTS`) is implementation-defined. On the other hand, the
170+
specified in `OPTS`) is implementation-defined. On the other hand, the
170171
generator function should not leave any side effects in the target variable on
171-
usage error.
172+
usage error. Note that the target variable might be cleared by the internal
173+
calls of `_comp_compgen`. To explicitly clear the target variable,
174+
`_comp_compgen_set` can be called without arguments.
172175

173176
Exported generators are defined with the names `_comp_xfunc_CMD_compgen_NAME`
174177
and called by `_comp_compgen [opts] -x CMD NAME args`. Internal generators are

0 commit comments

Comments
 (0)