Core Classes¶
Internal Click subclasses and configuration objects. Exposed publicly for advanced use cases such as subclassing or type-checking.
PycliferOption¶
Extends click.Option with is_global, context, and env-var binding support.
is_global=True— propagates this option to all subcommands automatically.context=True— marks the option as a context option: its value is passed to thecontext_factorycallable on@app_group, and it is accepted at any position in the command chain (even after a subcommand name).show_in_subcommand_help=True— whencontext=True, controls whether the option appears in subcommand--helpunder the Context Options panel. Set toFalseto hide an option from subcommand help while keeping its anywhere-passable behaviour.
pyclifer.PycliferOption
¶
Bases: StoreInMetaMixin, Option
Custom Click Option that can be marked as global for propagation.
Source code in src/pyclifer/core/classes.py
__init__(*args, is_global=False, context=False, show_in_subcommand_help=True, **kwargs)
¶
Initialize the option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for click.Option. |
()
|
is_global
|
bool
|
If True, this option will be propagated to subcommands. |
False
|
context
|
bool
|
If True, this option feeds ctx.obj construction and is accepted at any position in the command chain. |
False
|
show_in_subcommand_help
|
bool
|
If True, this option appears in subcommand help. |
True
|
**kwargs
|
Any
|
Keyword arguments for click.Option. |
{}
|
Source code in src/pyclifer/core/classes.py
resolve_envvar_value(ctx)
¶
Find the environment variable value, a global option using the one of the root.
A global option is the same option in every command, so it has one variable name: the one of the root group (CLI_REGION for an application named cli), not one built from the path of the command that receives it (CLI_LEAF_REGION). Without this, the variable depended on how the help is drawn, because click-extra writes the name of the root onto the option and rich-click does not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context of the command that parses this option. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The value of the variable, or None when it is not set. |
Source code in src/pyclifer/core/classes.py
PycliferGroup¶
Base Click group class used by app_group and group. Composes
EventsMixin + HandleResponseMixin + GlobalOptionsMixin.
pyclifer.PycliferGroup = PycliferExtraGroup
module-attribute
¶
CustomConfigOption¶
Extends click-extra's config option with multi-location Linux config file search
(/etc/<app>/, ~/.config/<app>/, etc.). It also emits the config.loaded event on its group
once the configuration is resolved (see Lifecycle events).
pyclifer.CustomConfigOption
¶
Bases: StoreInMetaMixin, ConfigOption
Custom ConfigOption to add support for /etc/
This class extends the default click-extra ConfigOption to include system-wide configuration directories following Linux conventions while maintaining cross-platform compatibility.
Source code in src/pyclifer/core/classes.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
__init__(*args, is_global=False, **kwargs)
¶
Initialize the custom config option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments. |
()
|
is_global
|
bool
|
If True, this option will be propagated to subcommands. |
False
|
**kwargs
|
Any
|
Keyword arguments. |
{}
|
Source code in src/pyclifer/core/classes.py
load_conf(ctx, param, path_pattern)
¶
Load the configuration, then emit config.loaded on the owning group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context of the group that owns this option. |
required |
param
|
Parameter
|
The parameter being processed. |
required |
path_pattern
|
Any
|
The configuration path pattern, or the no-config sentinel. |
required |
Source code in src/pyclifer/core/classes.py
get_default(ctx, call=True)
¶
Override get_default to fix rich-click help rendering.
rich-click fetches the default with call=False during help generation, which returns the raw bound method. We intercept this and force evaluation to display the actual path cleanly.
Source code in src/pyclifer/core/classes.py
default_pattern()
¶
Generate the default configuration search pattern.
Creates search patterns for configuration files, prioritizing Linux system directories when running on Linux platforms. Falls back to standard user configuration directories on other platforms.
Patterns are joined with "|" so that wcmatch's SPLIT flag (active on click-extra's ConfigOption) treats each path as a separate glob target.
Returns:
| Type | Description |
|---|---|
str
|
The pipe-separated glob pattern covering all config locations. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no click, context is available to determine CLI name. |
Source code in src/pyclifer/core/classes.py
search_and_read_file(pattern)
¶
Search each pipe-separated sub-pattern in order to preserve priority.
click-extra sorts the matches of a single pattern alphabetically, which would override the priority order built by default_pattern (system before user). Searching sub-patterns one at a time keeps that order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Pipe-separated glob patterns, or a single pattern or URL. |
required |
Yields:
| Type | Description |
|---|---|
tuple[Path | URL, str, str | None]
|
Triples of location, raw content and media type, in sub-pattern order. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When no sub-pattern matches any file. |
Source code in src/pyclifer/core/classes.py
read_and_parse_conf(pattern)
¶
Read every matching file and deep-merge them, the last one winning.
Sub-patterns are read in order, from the lowest to the highest priority (system before user), and the files of one directory are read in alphabetical order. Each file overrides the keys of the previous ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Pipe-separated glob patterns, or a single pattern or URL. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Path | URL | None, dict[str, Any] | None]
|
The location of the highest priority file and the merged configuration. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When no file matches the pattern. |
Source code in src/pyclifer/core/classes.py
PycliferTimerOption¶
Internal option class powering timer=True on @app_group. Subclasses click-extra's
TimerOption to integrate with pyclifer's output format: suppresses the text echo in
json/yaml mode and injects timing fields into Response.data via returns_response.
pyclifer.core.classes.PycliferTimerOption
¶
Bases: TimerOption
TimerOption integrated with pyclifer output format.
Skips the text echo in json/yaml mode — timing data is injected directly into the Response by returns_response instead.
Source code in src/pyclifer/core/classes.py
init_timer(ctx, param, value)
¶
Register the timer and store the context for deferred format check.
Source code in src/pyclifer/core/classes.py
print_timer()
¶
Print elapsed time unless the output format is json or yaml.
Output format is read at close time so that eager option processing order does not matter — meta is fully populated by then.