8from typing
import Any, Iterable, List, Optional
16 """Entry Point for completion of main and subcommand options."""
23 current = cwords[cword - 1]
27 parser = create_main_parser()
28 subcommands = list(commands_dict)
32 subcommand_name: Optional[str] =
None
34 if word
in subcommands:
35 subcommand_name = word
38 if subcommand_name
is not None:
40 if subcommand_name ==
"help":
47 if should_list_installed:
48 env = get_default_environment()
58 for dist
in installed:
62 should_list_installables = (
65 if should_list_installables:
70 subcommand = create_command(subcommand_name)
78 prev_opts = [
x.split(
"=")[0]
for x
in cwords[1 : cword - 1]]
79 options = [(x, v)
for (x, v)
in options
if x
not in prev_opts]
81 options = [(k, v)
for k, v
in options
if k.startswith(current)]
92 options = [(path, 0)
for path
in paths]
93 for option
in options:
96 if option[1]
and option[0][:2] ==
"--":
106 for opt
in flattened_opts:
115 print(
" ".join([x
for x
in subcommands
if x.startswith(current)]))