topmark.cli.options¶
Common Click option decorators and parsing utilities for TopMark.
This module centralizes reusable Click option definitions and CLI-focused parsing utilities so command implementations can remain thin and consistent.
Structure¶
- Small parsing helpers for
--*-frominputs and verbosity resolution. - Underscored spelling traps (e.g.
--include_from→ hint--include-from). - Reusable option-decorator builders used by CLI commands.
Conventions¶
- Public decorators are named
common_*_optionsor<domain>_*_options. - Parsing helpers are small, typed, and import-safe.
- Long option spellings come from
topmark.cli.keys.CliOpt. - Short option spellings come from
topmark.cli.keys.CliShortOpt.
StdinUse ¶
Bases: str, Enum
Identify which --*-from option (if any) consumes STDIN.
Values
NONE: Default; no --*-from option consumes STDIN.
FILES_FROM: --files-from - consumes STDIN (newline-delimited file paths).
INCLUDE_FROM: --include-from - consumes STDIN (newline-delimited glob patterns).
EXCLUDE_FROM: --exclude-from - consumes STDIN (newline-delimited glob patterns).
FromOptionValues
dataclass
¶
Values supplied through --*-from options.
Attributes:
| Name | Type | Description |
|---|---|---|
files_from |
list[str]
|
Values passed through |
include_from |
list[str]
|
Values passed through |
exclude_from |
list[str]
|
Values passed through |
FromOptionStdinText
dataclass
¶
STDIN text routed to at most one --*-from - option.
Attributes:
| Name | Type | Description |
|---|---|---|
files_from |
str | None
|
Raw STDIN text for |
include_from |
str | None
|
Raw STDIN text for |
exclude_from |
str | None
|
Raw STDIN text for |
split_nonempty_lines ¶
Split text into non-empty, non-comment lines.
Lines are stripped. Blank lines and lines starting with # are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
Raw text (possibly None). |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Cleaned, non-empty lines. |
Source code in src/topmark/cli/options.py
extend_with_stdin_lines ¶
Extend target with non-empty, non-comment lines from STDIN text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
list[str]
|
List to extend. |
required |
stdin_text
|
str | None
|
Raw text from STDIN (possibly None). |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The same list instance for convenience. |
Source code in src/topmark/cli/options.py
strip_dash_sentinels ¶
Remove '-' sentinels so downstream code never treats STDIN as a file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files_from
|
Iterable[str]
|
Values passed via |
required |
include_from
|
Iterable[str]
|
Values passed via |
required |
exclude_from
|
Iterable[str]
|
Values passed via |
required |
Returns:
| Type | Description |
|---|---|
FromOptionValues
|
Values from each |
Source code in src/topmark/cli/options.py
extract_stdin_for_from_options ¶
Return raw STDIN text for at most one --*-from - option.
If one of the options contains '-', this reads STDIN (unless stdin_text
is provided) and returns that text for the requesting option. If multiple
--*-from options request STDIN, a usage error is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files_from
|
Iterable[str]
|
Values passed via |
required |
include_from
|
Iterable[str]
|
Values passed via |
required |
exclude_from
|
Iterable[str]
|
Values passed via |
required |
stdin_text
|
str | None
|
Optional pre-read STDIN content (useful for tests). |
None
|
Returns:
| Type | Description |
|---|---|
FromOptionStdinText
|
Routed STDIN text for the requesting |
FromOptionStdinText
|
is non- |
Raises:
| Type | Description |
|---|---|
TopmarkCliUsageError
|
If multiple options request STDIN simultaneously. |
Source code in src/topmark/cli/options.py
normalize_verbosity ¶
Normalize an integer verbosity level from -v/--verbose counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose_count
|
int
|
Number of times |
required |
Returns:
| Type | Description |
|---|---|
int
|
Normalized verbosity level in the range 0..2. |
Source code in src/topmark/cli/options.py
option_with_underscore_traps ¶
Like click.option, but also traps underscored spellings.
For each canonical long option declaration of the form --foo-bar, this helper
also registers a hidden eager flag --foo_bar that raises a helpful error
suggesting the hyphenated spelling.
The trap is attached alongside the real option so call sites don't need to remember to register traps separately.
Trap options are always flags, even when the canonical option takes a value. This ensures underscored spellings are rejected immediately instead of being parsed as value-taking options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*param_decls
|
str
|
Click option declarations (e.g. |
()
|
**attrs
|
Unpack[_ClickOptionKwargs]
|
Keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[_P, _R]], Callable[_P, _R]]
|
A Click option decorator. |
Source code in src/topmark/cli/options.py
option_with_hidden_aliases_and_underscore_traps ¶
option_with_hidden_aliases_and_underscore_traps(
*param_decls,
hidden_aliases,
multiple=False,
callback=None,
help=None,
)
Like option_with_underscore_traps, with hidden compatibility aliases.
Hidden aliases are registered as separate hidden Click options that write to the same destination as the visible option. This keeps the compatibility aliases accepted by Click while omitting them from Click and Rich Click help output.
This helper intentionally exposes only the option attributes currently
needed by file-type filters. Keeping the signature narrow avoids ambiguous
TypedDict unpacking for the forced hidden=True alias option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*param_decls
|
str
|
Visible Click option declarations. The declarations must include an explicit destination name. |
()
|
hidden_aliases
|
tuple[str, ...]
|
Compatibility aliases accepted but hidden from help. |
required |
multiple
|
bool
|
Whether the visible and hidden options may be repeated. |
False
|
callback
|
Callable[..., object] | None
|
Optional Click callback applied to parsed option values. |
None
|
help
|
str | None
|
Human-facing help text for the visible option. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[_P, _R]], Callable[_P, _R]]
|
A Click option decorator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/topmark/cli/options.py
enum_value_help_text ¶
Render CLI-facing help text for enum option values.
CLI help prefers kebab-case values for readability. TopMark's configuration, Python API enum values, and machine-readable output use canonical underscore values when enum members are defined with underscores. This helper renders the CLI-facing value list, marks an optional default, and appends a short underscore/canonical-value note only when needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enum_cls
|
type[Enum]
|
Enum class whose members expose string values. |
required |
prefix
|
str
|
Optional text placed before the rendered value list. |
''
|
default
|
Enum | str | None
|
Optional enum member or raw value to mark as the default. |
None
|
suffix
|
str | None
|
Optional sentence appended after the alias/canonical-value note. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Help text suitable for inclusion in a Click option description. |
Source code in src/topmark/cli/options.py
common_text_output_verbosity_options ¶
Adds --verbose option to a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function with verbosity option added. |
Behavior
Adds count-based -v/--verbose detail controls for text output.
Source code in src/topmark/cli/options.py
common_text_output_quiet_options ¶
Adds --quiet option to a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function with quiet option added. |
Behavior
Adds boolean -q/--quiet suppression for text output.
Source code in src/topmark/cli/options.py
common_color_options ¶
Adds --color and --no-color options to a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function with color options added. |
Behavior
Adds --color with choices (auto, always, never). Adds --no-color flag that disables color output. These options control colorized terminal output.
Source code in src/topmark/cli/options.py
common_output_format_options ¶
Apply common output format options.
Adds the --output-format option which accepts OutputFormat values for human use
(text, markdown) and machine-readable formats (json, ndjson).
If not set, it will be resolved to text (ANSI-capable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_header_field_options ¶
Apply common header field selection and definition options.
Adds the folloiwng header field options: --header-fields,
--field-values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_include_exclude_from_options ¶
Apply common file selection and filtering options.
Adds the following file source options: --include-from, --exclude-from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_files_from_options ¶
Apply common file selection and filtering options.
Adds the following file source options: --files-from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
config_dump_files_from_options ¶
Apply config dump file selection and filtering options.
Adds the following file source options: --files-from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_stdin_content_mode_options ¶
Apply common file selection and filtering options.
Adds option --stdin-filename when processing file contents from STDIN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_file_filtering_options ¶
Apply common file selection and filtering pattern options.
Adds file inclusion / exclusion pattern options: --include, --exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_file_type_filtering_options ¶
Apply common file type selection and filtering options.
Adds file type filtering options: --include-file-types, --exclude-file-types.
The singular spellings remain accepted as hidden compatibility aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_apply_and_write_options ¶
Apply common file selection and filtering options.
Adds options such as --apply, --write-mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
render_diff_options ¶
Apply diff rendering options.
Adds the following option: --diff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
pipeline_reporting_options ¶
Apply summary/reporting options for pipeline-style commands.
Notes
--report is a human-facing per-file listing policy. It is ignored for
summary mode and machine-readable output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
registry_details_options ¶
Apply details mode output options for registry commands.
Adds the following option: --long.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
config_strict_options ¶
Add config strictness override options.
The CLI flags override the effective [config].strict value for the current run.
Source code in src/topmark/cli/options.py
config_pyproject_options ¶
Add --pyproject to generate config suitable for inclusion in pyproject.toml.
Source code in src/topmark/cli/options.py
config_root_options ¶
Add --root to mark generated config as a discovery root.
Source code in src/topmark/cli/options.py
common_config_resolution_options ¶
Apply common config resolution options to a Click command.
Adds --no-config and --config/-c options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
config_dump_provenance_options ¶
Apply config layered dump options.
Adds --show-layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
common_header_formatting_options ¶
Apply common header formatting options.
Adds --align-fields/--no-align-fields and --relative-to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |
Source code in src/topmark/cli/options.py
check_policy_options ¶
Attach check-only policy options.
These options control header insertion/update behavior and are only
meaningful for the topmark check pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
Decorated Click command function. |
Source code in src/topmark/cli/options.py
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | |
shared_policy_options ¶
Attach policy options shared by multiple pipeline commands.
These options affect common pipeline behavior such as file-type resolution
and are meaningful for topmark check, topmark strip, and topmark probe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
Decorated Click command function. |
Source code in src/topmark/cli/options.py
version_format_options ¶
Apply version formatting options.
Adds --align-fields/--no-align-fields, --header-format and --relative-to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable[_P, _R]
|
The Click command function to decorate. |
required |
Returns:
| Type | Description |
|---|---|
Callable[_P, _R]
|
The decorated function. |