73 group: click.Group, prefix: str =
"",
74) -> list[tuple[str, click.Command]]:
75 """Yield ``(qualified_name, command)`` for every non-hidden command."""
76 out: list[tuple[str, click.Command]] = []
77 ctx = click.Context(group)
78 for name
in group.list_commands(ctx):
79 sub = group.get_command(ctx, name)
80 if sub
is None or getattr(sub,
"hidden",
False):
82 qname = f
"{prefix}{name}"
83 out.append((qname, sub))
84 if isinstance(sub, click.Group):
143 missing: list[tuple[str, str]] = []
144 ctx = click.Context(cli)
145 for name
in cli.list_commands(ctx):
146 sub = cli.get_command(ctx, name)
147 if not isinstance(sub, click.Group)
or getattr(sub,
"hidden",
False):
149 rows = _COMMAND_FLAGS.get(name, [])
150 rendered =
" | ".join(f
"{flag} {desc}" for flag, desc
in rows)
151 sub_ctx = click.Context(sub)
152 for sub_name
in sub.list_commands(sub_ctx):
153 sub_cmd = sub.get_command(sub_ctx, sub_name)
154 if sub_cmd
is None or getattr(sub_cmd,
"hidden",
False):
156 if sub_name
not in rendered:
157 missing.append((name, sub_name))
159 assert not missing, (
160 "Drift detected — the following Click subcommands are missing "
161 "from their group's _COMMAND_FLAGS entry: " +
", ".join(
162 f
"{g}:{s}" for g, s
in missing
170 ctx = click.Context(cli)
171 top_level = set(cli.list_commands(ctx))
173 name: cli.get_command(ctx, name)
174 for name
in top_level
175 if isinstance(cli.get_command(ctx, name), click.Group)
178 stale: list[str] = []
179 for key
in _COMMAND_FLAGS:
182 if parts[0]
not in top_level:
185 group_name, sub_name = parts[0],
" ".join(parts[1:])
186 group = groups.get(group_name)
190 sub_ctx = click.Context(group)
191 if sub_name.split()[0]
not in group.list_commands(sub_ctx):
193 nested = group.get_command(sub_ctx, sub_name.split()[0])
194 if not isinstance(nested, click.Group):
198 "_COMMAND_FLAGS has keys that do not map to real commands: "