@rich_click.group(
cls=rich_click.RichGroup,
context_settings=GROUP_CONTEXT_SETTINGS,
invoke_without_command=True, # Always invoke the cli() function
help="Inspect, validate, and manage TopMark headers and configuration.",
epilog=render_examples_epilog(
examples=(
HelpExample(
summary="Validate headers in a project (dry-run)",
command_line=f"topmark {CliCmd.CHECK} src",
),
HelpExample(
summary="Apply header updates in place",
command_line=f"topmark {CliCmd.CHECK} --apply .",
),
HelpExample(
summary="Write a starter configuration file",
command_line=f"topmark {CliCmd.CONFIG} {CliCmd.CONFIG_INIT} > topmark.toml",
),
HelpExample(
summary="Validate the merged configuration",
command_line=f"topmark {CliCmd.CONFIG} check",
),
HelpExample(
summary="Inspect file types (machine-readable output)",
command_line=(
f"topmark {CliCmd.REGISTRY} {CliCmd.REGISTRY_FILETYPES} "
f"{CliOpt.OUTPUT_FORMAT}={OutputFormat.JSON.value}"
),
),
HelpExample(
summary="Print the installed TopMark version",
command_line=f"topmark {CliCmd.VERSION}",
),
),
),
)
@click.pass_context
def cli(
ctx: click.Context,
) -> None:
"""TopMark CLI entry point.
Bootstraps shared CLI state and delegates execution to subcommands.
When invoked without a subcommand, prints a short hint and the help text.
"""
# Check the Python version (may exit)
check_python_version()
# Subcommands now own verbosity/color options and call init_common_state().
# Ensure we still have a console for the root group help output.
state: TopmarkCliState = bootstrap_cli_state(ctx)
console: ConsoleProtocol = state.console
if ctx.invoked_subcommand is None:
console.print(ctx.get_help())