Completion
duho.completion
Shell completion script generation (bash/zsh/fish).
Decision (do not revisit): STATIC script generation -- these functions emit a self-contained completion script the user installs once, NOT a dynamic argcomplete-style hook that re-invokes the program on every Tab. Zero runtime dependency, zero per-invocation cost: a core differentiator vs. argcomplete.
All three emitters (bash, zsh, fish) share one parser-tree walk
(_walk) that turns a built argparse.ArgumentParser into a plain,
shell-agnostic CompletionSpec. Only the emitters know shell syntax.
Completion data is read off the built parser's private attrs
(parser._actions, parser._subparsers) -- the same internal contract
parsers.py already relies on elsewhere in this codebase.
__all__ = ['CompletionOption', 'CompletionPositional', 'CompletionSpec', 'bash', 'zsh', 'fish']
module-attribute
CompletionOption(flags, takes_value, choices=None, is_path=False)
dataclass
One optional argument (e.g. --name/-n).
choices = None
class-attribute
instance-attribute
flags
instance-attribute
is_path = False
class-attribute
instance-attribute
takes_value
instance-attribute
CompletionPositional(name, choices=None, is_path=False)
dataclass
One positional argument.
choices = None
class-attribute
instance-attribute
is_path = False
class-attribute
instance-attribute
name
instance-attribute
CompletionSpec(prog, options=list(), positionals=list(), subcommands=dict())
dataclass
Shell-agnostic view of a single (sub)parser and its subcommand tree.
options = _dc.field(default_factory=list)
class-attribute
instance-attribute
positionals = _dc.field(default_factory=list)
class-attribute
instance-attribute
prog
instance-attribute
subcommands = _dc.field(default_factory=dict)
class-attribute
instance-attribute
bash(parser, prog=None)
Emit a self-contained bash completion script for parser.
Registers complete -F _<prog> <prog>. Choices use compgen -W,
Path-typed args fall back to compgen -f/-d (native file/dir
completion), non-Path/non-choice args get no candidates (bash's default
filename completion still applies).
Source code in src/duho/completion.py
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 | |
fish(parser, prog=None)
Emit a fish completion script (complete -c <prog> ... lines) for parser.
Choices become -a, value-taking options get -r (require an
argument), Path-typed options additionally get -F to enable fish's
native file completion; subcommand-scoped rules are gated on
__fish_seen_subcommand_from.
Source code in src/duho/completion.py
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 353 354 355 356 357 358 359 360 361 362 363 364 | |
zsh(parser, prog=None)
Emit a #compdef-style zsh completion script for parser.
Uses _arguments/_describe: subcommand names and option choices are
rendered as (a b c) value lists; Path-typed args delegate to _files.
Source code in src/duho/completion.py
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 | |