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 option --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.
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
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.
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
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
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. |