Module
clak
Clak: A Command Line Application Kit.
Clak is a framework for building command line applications in Python. It extends and enhances Python's argparse with features like:
- Simplified parser composition and inheritance
- Rich command completion support
- XDG Base Directory path flags and config-file loading (
XDGConfigMixin) - Structured logging configuration
- Recursive subcommand handling
Canonical public API (import from clak):
- Parser: root/command class (auto-dispatches on init unless parse=False)
- Argument: positional or optional argument descriptor
- Arg / Opt: optional sugar for positionals vs flags (Argument still accepts both)
- Command: nested subcommand descriptor (alias of SubParser)
Optional mixins (also from clak): LoggingOptMixin, RichHelpMixin,
Show/List/Pprint/Raw/Markdown/Rst/Data/CompositeViewMixin, completion,
XDGConfigMixin.
Secondary entry points: clak.exception, clak.views (view classes),
clak.comp (mixins). Internal layout: clak.core, clak.runtime,
clak.views, clak.comp. Deep module paths remain import-compatible.
Arg
Bases: Argument
Optional sugar for a positional argument.
Same *args / **kwargs as :class:Argument, but at least one
positional name is required (no leading -). Empty Arg() is
rejected; dest-derived flags belong on Opt / Argument.
Argument still accepts both positionals and flags.
Source code in clak/core/descriptors.py
Argument
Bases: ArgParseItem
Represents an argument that can be added to an argument parser.
Handles both positional arguments and optional flags, choosing the
appropriate argparse form from the flag names. Optional helpers
:class:Arg (positionals) and :class:Opt (flags) reject mixed names.
Most keyword arguments are passed through to
:meth:argparse.ArgumentParser.add_argument. Clak-only kwargs (stripped
before argparse):
argument_group/option_group: Optional title for a help section (parser.add_argument_group). Same title reuses one section; pick the name that matches what you are grouping. Do not set both on one Argument.exclusive_group: Shared key for argparse mutual exclusion (add_mutually_exclusive_group). Same key reuses one XOR set (required=False). May nest under a help section when a help-group kwarg is also set.
Source code in clak/core/descriptors.py
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 | |
attach_arg_to_parser(key, config)
Create and add an argument to the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The argument key/name |
required |
config
|
ParserNode
|
The parser configuration object |
required |
Returns:
| Type | Description |
|---|---|
Action
|
argparse.Action: The created argument parser action |
Source code in clak/core/descriptors.py
CompCmdRender
Bases: CompRenderCmdMixin, Parser
Command completion renderer class.
Combines the CompRenderCmdMixin with the base Parser to create a class that can render command completion code. This class provides the core functionality for generating shell completion scripts for command-line tools.
Key features: - Generates shell completion code for bash/tcsh/fish - Supports external completion scripts - Configurable executable names - Default completion behavior
Source code in clak/comp/completion.py
CompRenderCmdMixin
Bases: CompRenderMixin
Completion command support
Source code in clak/comp/completion.py
cli_run(ctx, **kwargs)
Command completion support mixin.
Adds command completion support to parsers by providing arguments to configure shell completion behavior:
- --no-defaults: Disable fallback to readline defaults (bash only)
- --complete-arguments: Custom completion arguments (bash only)
- --shell: Target shell (bash, zsh, tcsh, fish, powershell)
- --executable: Name of executable to complete
The mixin generates the appropriate shell completion code when run. Supports bash (default), zsh, tcsh, fish and powershell shells.
Example
my-app completion # Outputs bash completion code my-app completion --shell zsh # Outputs zsh completion code
Source code in clak/comp/completion.py
CompRenderOptMixin
Bases: CompRenderMixin
Completion options support mixin.
Adds a --completion flag that prints bash argcomplete shellcode
instead of running the command. Prefer :class:CompCmdRender as a
completion subcommand when you need --shell / --executable.
Example::
my-app --completion
Source code in clak/comp/completion.py
cli_run(ctx, **kwargs)
Print bash completion shellcode when --completion is set.
Example::
my-app --completion
Source code in clak/comp/completion.py
CompositeViewMixin
Bases: TextLayoutOptMixin, TableViewOptMixin
CLI flags for multi-section :class:~clak.views.CompositeView output.
Adds table options, --expand-keys, --format-scope, --width,
and --line-length. Does not set Meta.cli_view: return a
CompositeView(...) from cli_run. Table flags apply to the primary
section only. --line-length applies to text/pprint sections only.
--expand-keys is for a ListView primary; hide it with
Meta.view_cli_options when the primary is ShowView.
--format is table-scoped (view / yaml / json / csv);
markdown source is in --format-scope all envelopes, not --format raw.
Source code in clak/comp/views.py
DataViewMixin
Bases: _ViewMixinBase
Auto-render command results with :class:~clak.views.DataView.
Adds --format (json / yaml), --compact / --no-compact,
--color / --no-color, and --anchors / --no-anchors.
Syntax theme: Meta.view_syntax_theme or CLAK_SYNTAX_THEME, else
ansi_dark. Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
ListViewMixin
Bases: TableViewOptMixin
Auto-render command results with :class:~clak.views.ListView.
Adds --columns, --add-index / --no-add-index,
--expand-keys / --no-expand-keys, --format,
--sort-columns, --sort-mode, --width, and --wrap.
Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
LoggingOptMixin
Bases: PluginHelpers
Logging options support
Source code in clak/comp/logging.py
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
add_arguments(arguments=None)
Format --log-colors help with Meta.log_colors_env, then register.
Source code in clak/comp/logging.py
assemble_user_config(configs)
Build cumulative verbosity tiers from Meta.log_levels.
Explicit entries use LEVEL|logger. Legacy configurations containing
only logger names are expanded to INFO and DEBUG tiers for each group.
Source code in clak/comp/logging.py
cli_hook__logging(instance, ctx, **_)
Inject or create logger into instance
Source code in clak/comp/logging.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
select_user_config(user_config, req=0)
Select user config from requested level
Source code in clak/comp/logging.py
test_logger(instance=None)
Test the logger by sending test messages at different log levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
object | None
|
The instance to test logging for. If None, uses self. |
None
|
Source code in clak/comp/logging.py
MarkdownViewMixin
Bases: TextViewOptMixin
Auto-render command results with :class:~clak.views.MarkdownView.
Adds --format (view / raw) and --line-length.
Syntax theme: Meta.view_syntax_theme or CLAK_SYNTAX_THEME, else
ansi_dark. Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
Opt
Bases: Argument
Optional sugar for an option flag.
Same *args / **kwargs as :class:Argument. When names are
given, every name must start with - / --. Empty Opt() is
allowed: the attribute name becomes a dest-derived flag (--attr
or -x). Argument still accepts both positionals and flags.
Source code in clak/core/descriptors.py
Parser
Bases: ParserNode
A simplified parser class that extends ParserNode.
This class provides a more streamlined interface to ParserNode by: - Automatically parsing arguments on initialization - Maintaining compatibility with legacy argument parser names - Providing simpler command/argument creation methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments passed to ParserNode |
()
|
parse
|
bool
|
Whether to automatically parse arguments on init, only on root nodes |
True
|
**kwargs
|
Any
|
Keyword arguments passed to ParserNode |
{}
|
Source code in clak/core/parser.py
ParserNode
Bases: Node
An extensible argument parser that can be inherited to create custom CLIs.
This class provides a framework for building complex command-line interfaces with: - Hierarchical subcommands - Automatic help generation - Plugin support - Custom argument types - Exception handling
The parser can be extended by: 1. Subclassing and adding Argument instances as class attributes 2. Adding SubParser instances to create command hierarchies 3. Implementing cli_run() for command execution 4. Implementing cli_group() for command group behavior
Attributes:
| Name | Type | Description |
|---|---|---|
arguments_dict |
dict
|
Dictionary of argument name to ArgParseItem |
children |
dict
|
Dictionary of subcommand name to subcommand class |
meta__name |
str
|
ParserNode name |
Source code in clak/core/parser.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
subparsers
property
Lazily create and return the subparsers object.
__init__(add_help=True, parent=None, name=None, key=None, parser=None, inject_as_subparser=True, proc_name=None)
Initialize the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
add_help
|
bool
|
Whether to add help flags |
True
|
parent
|
ParserNode
|
Parent parser instance |
None
|
name
|
str
|
ParserNode name |
None
|
key
|
str
|
ParserNode key |
None
|
parser
|
ArgumentParser
|
Existing parser to use |
None
|
inject_as_subparser
|
bool
|
Ignored. Kept so existing callers
do not TypeError. Only |
True
|
proc_name
|
str
|
Process name |
None
|
Source code in clak/core/parser.py
add_argument(key, arg=None, **kwargs)
Add an argument to this parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key/name for the argument |
required |
arg
|
Argument
|
The argument object to add |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to add_argument() |
{}
|
This method adds a new argument to the parser. The argument can be either a positional argument or an optional flag, determined by the Argument object.
Source code in clak/core/parser.py
add_arguments(arguments=None)
Initialize all argument options defined for this parser.
This method: 1. Collects arguments from arguments_dict 2. Collects arguments defined as class attributes 3. Adds internal arguments like cli_self 4. Creates all argument parser entries
Source code in clak/core/parser.py
add_subcommand(key, arg=None, **kwargs)
add_subcommands(subcommands=None)
Initialize all subcommands defined for this parser.
This method: 1. Collects subcommands from children dictionary 2. Collects Command instances defined as class attributes 3. Creates parser entries for all subcommands
Source code in clak/core/parser.py
clean_terminate(err, known_exceptions=None)
Handle program termination based on exception type.
Processing order (Paasify-style chain):
Meta.known_exceptionson the root parser (class or(class, handler))Meta.exception_handlers(third-party libs: YAML, shell, …)- Built-in Clak exceptions
- Broken pipe (
| head/| tail) - quiet exit - Common OS errors
If nothing matches, return and let dispatch() report an unexpected bug.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
err
|
Exception
|
The exception that triggered termination |
required |
known_exceptions
|
list
|
List of exception types to handle specially |
None
|
Source code in clak/core/parser.py
cli_execute(args=None)
Execute the command with given arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Optional[Dict[str, Any]]
|
Arguments to parse |
None
|
Raises:
| Type | Description |
|---|---|
ClakParseError
|
If argument parsing fails |
NotImplementedError
|
If command has no implementation |
Source code in clak/core/parser.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 | |
cli_exit(status=0, message=None)
Exit the CLI application with given status and message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
int
|
Exit status code |
0
|
message
|
str
|
Optional message to display |
None
|
Source code in clak/core/parser.py
cli_exit_error(message)
Exit the CLI application with an error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message to display |
required |
cli_group(ctx, **_)
Execute group-level command behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
SimpleNamespace
|
Command context object |
required |
**_
|
Any
|
Unused keyword arguments |
{}
|
cli_run(**kwargs)
Execute the command implementation.
This method should be overridden by subclasses to implement command behavior. The base implementation shows help for non-leaf nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional keyword arguments from command line |
{}
|
Raises:
| Type | Description |
|---|---|
ClakNotImplementedError
|
If leaf node has no implementation |
Source code in clak/core/parser.py
create_parser()
Create a new parser
Source code in clak/core/parser.py
dispatch(args=None, trace=False, **_)
Main dispatch function for command execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Optional[Union[str, List[str], Dict[str, Any]]]
|
Arguments to parse |
None
|
**_
|
Any
|
Unused keyword arguments |
{}
|
Source code in clak/core/parser.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
get_fname(attr='key')
get_help_formatter_class()
Return the argparse HelpFormatter class for this node.
Mixins set meta__help_formatter (or Meta.help_formatter).
Unset walks parents, then RichRecursiveHelpFormatter.
Opt out with Meta.help_formatter = RecursiveHelpFormatter.
Source code in clak/core/parser.py
parse_args(args=None)
Parse command line arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Optional[Union[str, List[str], Dict[str, Any]]]
|
Arguments to parse, can be:
- None: Use sys.argv[1:]
- str: Shell-style split via |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Namespace |
Namespace
|
Parsed argument namespace |
Raises:
| Type | Description |
|---|---|
ValueError
|
If args is invalid type |
Source code in clak/core/parser.py
show_epilog()
show_help()
PprintViewMixin
Bases: TextLayoutOptMixin
Auto-render command results with :class:~clak.views.PprintView.
Adds --line-length. Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
RawViewMixin
Bases: TextLayoutOptMixin
Auto-render command results with :class:~clak.views.RawView.
Adds --line-length. Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
RecursiveHelpFormatter
Bases: RawDescriptionHelpFormatter
A recursive help formatter to help command discovery.
Source code in clak/core/argparse_.py
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
format_help()
Drop an empty positional arguments: heading.
Subparsers live in that argparse group, but Clak prints them under
subcommands:. When there are no real positionals, the empty
heading is noise.
Source code in clak/core/argparse_.py
RichHelpMixin
Same default as Parser (Rich help formatter).
Optional. Useful to re-opt-in a child after a parent sets
Meta.help_formatter = RecursiveHelpFormatter.
Source code in clak/comp/help.py
RstViewMixin
Bases: TextViewOptMixin
Auto-render command results with :class:~clak.views.RstView.
Adds --format (view / raw) and --line-length.
Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
ShowViewMixin
Bases: TableViewOptMixin
Auto-render command results with :class:~clak.views.ShowView.
Adds --columns, --add-index / --no-add-index,
--format, --sort-columns, --sort-mode, --width,
and --wrap.
Configure exposed flags with Meta.view_cli_options.
Source code in clak/comp/views.py
SubParser
Bases: ArgParseItem
Represents a subcommand parser that can be added to a parent parser.
This class handles creation of nested command structures, allowing for hierarchical command-line interfaces. It supports both subparser and injection modes.
Most keyword arguments are passed through to
:meth:argparse._SubParsersAction.add_parser. Clak-only kwargs (stripped
before argparse):
command_group: Optional key for a subcommand help section. Pair withMeta.command_groupson the parent Parser. Formatter metadata only; not a secondadd_subparsers. Commands with no key stay under leftoversubcommands:.
Attributes:
| Name | Type | Description |
|---|---|---|
meta__help_flags |
bool
|
Whether to enable -h and --help support |
meta__usage |
str
|
Custom usage message |
meta__description |
str
|
Custom description message |
meta__epilog |
str
|
Custom epilog message |
Source code in clak/core/descriptors.py
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
attach_sub_to_parser(key, config)
Create a subcommand parser for this command.
Creates a new subparser for the command and configures it with the appropriate help text and options. Validates that the command name is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Name of the subcommand |
required |
config
|
ParserNode
|
Parent parser configuration object |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If command name contains spaces |
Returns:
| Name | Type | Description |
|---|---|---|
ParserNode |
ParserNode
|
The created child parser instance |
Source code in clak/core/descriptors.py
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
XDGConfigMixin
XDG path flags and config-file loading.
Adds:
- --conf-file: $XDG_CONFIG_HOME/<app>/config.yaml
- --data-dir: $XDG_DATA_HOME/<app> (hidden)
- --cache-dir: $XDG_CACHE_HOME/<app> (hidden)
- --log-dir: $XDG_CACHE_HOME/<app>/logs (hidden)
<app> comes from Meta.app_name, else the parser name / class name.
Defaults respect $XDG_CONFIG_HOME, $XDG_DATA_HOME, and
$XDG_CACHE_HOME when set.
On dispatch, cli_hook__config loads --conf-file (JSON always;
YAML with the config extra). Missing file yields {} unless
Meta.config_required is true. Loaded data is available as
ctx.config (dict) and cli_root.config (attribute namespace).
Source code in clak/comp/config.py
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 | |
add_arguments(arguments=None)
Apply XDG defaults from app name / env, then register arguments.
Source code in clak/comp/config.py
cli_hook__config(instance, ctx, **_)
Load --conf-file once and expose it on ctx / root.