click 8.2.0__tar.gz → 8.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. {click-8.2.0 → click-8.2.2}/CHANGES.rst +31 -0
  2. {click-8.2.0 → click-8.2.2}/PKG-INFO +5 -3
  3. {click-8.2.0 → click-8.2.2}/README.md +3 -1
  4. click-8.2.2/docs/_static/click-icon.svg +11 -0
  5. click-8.2.2/docs/_static/click-logo.svg +18 -0
  6. click-8.2.2/docs/_static/click-name.svg +24 -0
  7. {click-8.2.0 → click-8.2.2}/docs/advanced.rst +2 -257
  8. click-8.2.2/docs/click-concepts.rst +67 -0
  9. {click-8.2.0 → click-8.2.2}/docs/commands-and-groups.rst +84 -11
  10. {click-8.2.0 → click-8.2.2}/docs/complex.rst +4 -0
  11. {click-8.2.0 → click-8.2.2}/docs/conf.py +3 -2
  12. click-8.2.2/docs/contrib.md +45 -0
  13. click-8.2.0/docs/documentation.rst → click-8.2.2/docs/documentation.md +72 -62
  14. {click-8.2.0 → click-8.2.2}/docs/entry-points.rst +3 -2
  15. click-8.2.2/docs/extending-click.rst +138 -0
  16. click-8.2.2/docs/faqs.md +39 -0
  17. {click-8.2.0 → click-8.2.2}/docs/index.rst +47 -17
  18. click-8.2.0/docs/options.rst → click-8.2.2/docs/options.md +140 -75
  19. {click-8.2.0 → click-8.2.2}/docs/parameter-types.rst +4 -5
  20. click-8.2.2/docs/parameters.md +55 -0
  21. click-8.2.2/docs/support-multiple-versions.md +62 -0
  22. click-8.2.2/docs/unicode-support.md +100 -0
  23. click-8.2.2/docs/utils.md +390 -0
  24. click-8.2.2/docs/virtualenv.md +58 -0
  25. click-8.2.2/docs/why.md +106 -0
  26. click-8.2.2/docs/wincmd.md +47 -0
  27. click-8.2.2/pyproject.toml +208 -0
  28. {click-8.2.0 → click-8.2.2}/src/click/_termui_impl.py +1 -1
  29. {click-8.2.0 → click-8.2.2}/src/click/_winconsole.py +3 -2
  30. {click-8.2.0 → click-8.2.2}/src/click/core.py +70 -26
  31. {click-8.2.0 → click-8.2.2}/src/click/exceptions.py +3 -3
  32. {click-8.2.0 → click-8.2.2}/src/click/shell_completion.py +23 -3
  33. {click-8.2.0 → click-8.2.2}/src/click/testing.py +22 -2
  34. {click-8.2.0 → click-8.2.2}/src/click/types.py +57 -13
  35. {click-8.2.0 → click-8.2.2}/src/click/utils.py +1 -1
  36. {click-8.2.0 → click-8.2.2}/tests/test_arguments.py +9 -13
  37. {click-8.2.0 → click-8.2.2}/tests/test_basic.py +9 -5
  38. {click-8.2.0 → click-8.2.2}/tests/test_chain.py +2 -2
  39. {click-8.2.0 → click-8.2.2}/tests/test_imports.py +16 -15
  40. {click-8.2.0 → click-8.2.2}/tests/test_options.py +388 -5
  41. {click-8.2.0 → click-8.2.2}/tests/test_shell_completion.py +105 -0
  42. {click-8.2.0 → click-8.2.2}/tests/test_termui.py +2 -2
  43. {click-8.2.0 → click-8.2.2}/tests/test_testing.py +20 -1
  44. {click-8.2.0 → click-8.2.2}/tests/test_types.py +6 -1
  45. {click-8.2.0 → click-8.2.2}/tests/test_utils.py +14 -1
  46. click-8.2.2/uv.lock +1222 -0
  47. click-8.2.0/docs/Makefile +0 -20
  48. click-8.2.0/docs/_static/click-icon.png +0 -0
  49. click-8.2.0/docs/_static/click-logo-sidebar.png +0 -0
  50. click-8.2.0/docs/_static/click-logo.png +0 -0
  51. click-8.2.0/docs/contrib.rst +0 -58
  52. click-8.2.0/docs/make.bat +0 -36
  53. click-8.2.0/docs/parameters.rst +0 -58
  54. click-8.2.0/docs/unicode-support.rst +0 -112
  55. click-8.2.0/docs/utils.rst +0 -408
  56. click-8.2.0/docs/virtualenv.rst +0 -54
  57. click-8.2.0/docs/why.rst +0 -146
  58. click-8.2.0/docs/wincmd.rst +0 -64
  59. click-8.2.0/pyproject.toml +0 -105
  60. click-8.2.0/requirements/build.in +0 -1
  61. click-8.2.0/requirements/build.txt +0 -12
  62. click-8.2.0/requirements/dev.in +0 -6
  63. click-8.2.0/requirements/dev.txt +0 -225
  64. click-8.2.0/requirements/docs.in +0 -5
  65. click-8.2.0/requirements/docs.txt +0 -85
  66. click-8.2.0/requirements/tests.in +0 -1
  67. click-8.2.0/requirements/tests.txt +0 -14
  68. click-8.2.0/requirements/typing.in +0 -3
  69. click-8.2.0/requirements/typing.txt +0 -26
  70. click-8.2.0/tox.ini +0 -61
  71. {click-8.2.0 → click-8.2.2}/LICENSE.txt +0 -0
  72. {click-8.2.0 → click-8.2.2}/docs/api.rst +0 -0
  73. {click-8.2.0 → click-8.2.2}/docs/arguments.rst +0 -0
  74. {click-8.2.0 → click-8.2.2}/docs/changes.rst +0 -0
  75. {click-8.2.0 → click-8.2.2}/docs/commands.rst +0 -0
  76. {click-8.2.0 → click-8.2.2}/docs/exceptions.rst +0 -0
  77. {click-8.2.0 → click-8.2.2}/docs/handling-files.rst +0 -0
  78. {click-8.2.0 → click-8.2.2}/docs/license.rst +0 -0
  79. {click-8.2.0 → click-8.2.2}/docs/option-decorators.rst +0 -0
  80. {click-8.2.0 → click-8.2.2}/docs/prompts.rst +0 -0
  81. {click-8.2.0 → click-8.2.2}/docs/quickstart.rst +0 -0
  82. {click-8.2.0 → click-8.2.2}/docs/setuptools.rst +0 -0
  83. {click-8.2.0 → click-8.2.2}/docs/shell-completion.rst +0 -0
  84. {click-8.2.0 → click-8.2.2}/docs/testing.md +0 -0
  85. {click-8.2.0 → click-8.2.2}/src/click/__init__.py +0 -0
  86. {click-8.2.0 → click-8.2.2}/src/click/_compat.py +0 -0
  87. {click-8.2.0 → click-8.2.2}/src/click/_textwrap.py +0 -0
  88. {click-8.2.0 → click-8.2.2}/src/click/decorators.py +0 -0
  89. {click-8.2.0 → click-8.2.2}/src/click/formatting.py +0 -0
  90. {click-8.2.0 → click-8.2.2}/src/click/globals.py +0 -0
  91. {click-8.2.0 → click-8.2.2}/src/click/parser.py +0 -0
  92. {click-8.2.0 → click-8.2.2}/src/click/py.typed +0 -0
  93. {click-8.2.0 → click-8.2.2}/src/click/termui.py +0 -0
  94. {click-8.2.0 → click-8.2.2}/tests/conftest.py +0 -0
  95. {click-8.2.0 → click-8.2.2}/tests/test_command_decorators.py +0 -0
  96. {click-8.2.0 → click-8.2.2}/tests/test_commands.py +0 -0
  97. {click-8.2.0 → click-8.2.2}/tests/test_compat.py +0 -0
  98. {click-8.2.0 → click-8.2.2}/tests/test_context.py +0 -0
  99. {click-8.2.0 → click-8.2.2}/tests/test_custom_classes.py +0 -0
  100. {click-8.2.0 → click-8.2.2}/tests/test_defaults.py +0 -0
  101. {click-8.2.0 → click-8.2.2}/tests/test_formatting.py +0 -0
  102. {click-8.2.0 → click-8.2.2}/tests/test_info_dict.py +0 -0
  103. {click-8.2.0 → click-8.2.2}/tests/test_normalization.py +0 -0
  104. {click-8.2.0 → click-8.2.2}/tests/test_parser.py +0 -0
  105. {click-8.2.0 → click-8.2.2}/tests/typing/typing_aliased_group.py +0 -0
  106. {click-8.2.0 → click-8.2.2}/tests/typing/typing_confirmation_option.py +0 -0
  107. {click-8.2.0 → click-8.2.2}/tests/typing/typing_group_kw_options.py +0 -0
  108. {click-8.2.0 → click-8.2.2}/tests/typing/typing_help_option.py +0 -0
  109. {click-8.2.0 → click-8.2.2}/tests/typing/typing_options.py +0 -0
  110. {click-8.2.0 → click-8.2.2}/tests/typing/typing_password_option.py +0 -0
  111. {click-8.2.0 → click-8.2.2}/tests/typing/typing_progressbar.py +0 -0
  112. {click-8.2.0 → click-8.2.2}/tests/typing/typing_simple_example.py +0 -0
  113. {click-8.2.0 → click-8.2.2}/tests/typing/typing_version_option.py +0 -0
@@ -1,5 +1,36 @@
1
1
  .. currentmodule:: click
2
2
 
3
+ Version 8.2.2
4
+ -------------
5
+
6
+ Released 2025-07-31
7
+
8
+ - Fix reconciliation of `default`, `flag_value` and `type` parameters for
9
+ flag options, as well as parsing and normalization of environment variables.
10
+ :issue:`2952` :pr:`2956`
11
+ - Fix typing issue in ``BadParameter`` and ``MissingParameter`` exceptions for the
12
+ parameter ``param_hint`` that did not allow for a sequence of string where the
13
+ underlying functino ``_join_param_hints`` allows for it. :issue:`2777` :pr:`2990`
14
+ - Use the value of ``Enum`` choices to render their default value in help
15
+ screen. Refs :issue:`2911` :pr:`3004`
16
+ - Fix completion for the Z shell (``zsh``) for completion items containing
17
+ colons. :issue:`2703` :pr:`2846`
18
+ - Don't include envvar in error hint when not configured. :issue:`2971` :pr:`2972`
19
+ - Fix a rare race in ``click.testing.StreamMixer``'s finalization that manifested
20
+ as a ``ValueError`` on close in a multi-threaded test session.
21
+ :issue:`2993` :pr:`2991`
22
+
23
+ Version 8.2.1
24
+ -------------
25
+
26
+ Released 2025-05-20
27
+
28
+ - Fix flag value handling for flag options with a provided type. :issue:`2894`
29
+ :issue:`2897` :pr:`2930`
30
+ - Fix shell completion for nested groups. :issue:`2906` :pr:`2907`
31
+ - Flush ``sys.stderr`` at the end of ``CliRunner.invoke``. :issue:`2682`
32
+ - Fix EOF handling for stdin input in CliRunner. :issue:`2787`
33
+
3
34
  Version 8.2.0
4
35
  -------------
5
36
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: click
3
- Version: 8.2.0
3
+ Version: 8.2.2
4
4
  Summary: Composable command line interface toolkit
5
5
  Maintainer-email: Pallets <contact@palletsprojects.com>
6
6
  Requires-Python: >=3.10
@@ -13,13 +13,15 @@ Classifier: Programming Language :: Python
13
13
  Classifier: Typing :: Typed
14
14
  License-File: LICENSE.txt
15
15
  Requires-Dist: colorama; platform_system == 'Windows'
16
- Project-URL: Changes, https://click.palletsprojects.com/changes/
16
+ Project-URL: Changes, https://click.palletsprojects.com/page/changes/
17
17
  Project-URL: Chat, https://discord.gg/pallets
18
18
  Project-URL: Documentation, https://click.palletsprojects.com/
19
19
  Project-URL: Donate, https://palletsprojects.com/donate
20
20
  Project-URL: Source, https://github.com/pallets/click/
21
21
 
22
- # $ click_
22
+ <div align="center"><img src="https://raw.githubusercontent.com/pallets/click/refs/heads/stable/docs/_static/click-name.svg" alt="" height="150"></div>
23
+
24
+ # Click
23
25
 
24
26
  Click is a Python package for creating beautiful command line interfaces
25
27
  in a composable way with as little code as necessary. It's the "Command
@@ -1,4 +1,6 @@
1
- # $ click_
1
+ <div align="center"><img src="https://raw.githubusercontent.com/pallets/click/refs/heads/stable/docs/_static/click-name.svg" alt="" height="150"></div>
2
+
3
+ # Click
2
4
 
3
5
  Click is a Python package for creating beautiful command line interfaces
4
6
  in a composable way with as little code as necessary. It's the "Command
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="100%" height="100%" viewBox="0 0 500 500" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
4
+ <rect id="Icon" x="0" y="0" width="500" height="500" style="fill:none;"/>
5
+ <g>
6
+ <path d="M448.569,446.761l-66.389,49.07c-3.528,2.565 -8.018,4.169 -12.508,4.169l-136.626,-0c-19.243,-0 -28.223,-23.733 -14.112,-36.562l54.843,-49.07c3.849,-3.528 8.66,-5.452 14.112,-5.452l147.851,-0c20.526,-0 28.865,25.657 12.829,37.845Z" style="fill:#5c549e;fill-rule:nonzero;"/>
7
+ <path d="M192.956,406.03l-91.404,84.028c-6.415,6.414 -15.074,9.942 -23.734,9.942c-8.659,-0 -17.318,-3.528 -23.733,-9.942c-13.47,-13.47 -13.47,-34.317 0,-47.467l32.713,-36.561l106.158,-0Z" style="fill:#5c549e;fill-rule:nonzero;"/>
8
+ <path d="M328.299,216.485l-113.855,-102.309l-109.685,-0l124.118,135.343l-124.118,135.343l108.723,-0.321l114.817,-101.988c8.66,-9.301 13.15,-21.167 12.829,-33.355c0.321,-11.225 -4.169,-23.412 -12.829,-32.713Z" style="fill:#5c549e;fill-rule:nonzero;"/>
9
+ <path d="M191.994,93.97l-91.405,-84.028c-6.414,-6.414 -15.073,-9.942 -23.733,-9.942c-8.659,0 -17.319,3.528 -23.733,9.942c-13.47,13.47 -13.47,34.317 0,47.467l33.034,36.561l105.837,0Z" style="fill:#5c549e;fill-rule:nonzero;"/>
10
+ </g>
11
+ </svg>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="100%" height="100%" viewBox="0 0 500 500" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
4
+ <rect id="Logo" x="0" y="0" width="500" height="500" style="fill:none;"/>
5
+ <g>
6
+ <path id="Box" d="M500,50l0,400c0,27.596 -22.404,50 -50,50l-400,0c-27.596,0 -50,-22.404 -50,-50l0,-400c0,-27.596 22.404,-50 50,-50l400,0c27.596,0 50,22.404 50,50Z" style="fill:url(#_Linear1);"/>
7
+ <path id="Shadow" d="M500,432.911l0,17.089c0,27.596 -22.404,50 -50,50l-211.576,0l-105.636,-105.637c3.812,3.641 8.857,5.637 13.903,5.637c5.196,0 10.391,-2.117 14.24,-5.965l54.843,-50.417l-40.218,-0l-12.701,-12.701l65.234,-0.192l68.891,-61.193c5.195,-5.581 7.889,-12.701 7.697,-20.013c0.192,-6.735 -2.502,-14.048 -7.697,-19.628l203.02,203.02Zm-284.804,-276.529l12.124,12.123l-63.503,0l-12.123,-12.123l63.502,0Zm153.945,211.674c9.622,-7.312 4.619,-22.706 -7.697,-22.706l-88.711,-0c-3.271,-0 -6.157,1.154 -8.467,3.271l-32.905,29.442c-8.467,7.697 -3.079,21.937 8.467,21.937l81.975,0c2.694,0 5.388,-0.962 7.505,-2.502l39.833,-29.442Z" style="fill:#493e5e;"/>
8
+ <g id="Icon">
9
+ <path d="M369.141,368.056l-39.833,29.442c-2.117,1.54 -4.811,2.502 -7.505,2.502l-81.975,0c-11.546,0 -16.934,-14.24 -8.467,-21.937l32.905,-29.442c2.31,-2.117 5.196,-3.271 8.467,-3.271l88.711,-0c12.316,-0 17.319,15.394 7.697,22.706Z" style="fill:#fff;fill-rule:nonzero;"/>
10
+ <path d="M215.774,343.618l-54.843,50.417c-3.849,3.848 -9.044,5.965 -14.24,5.965c-5.196,0 -10.391,-2.117 -14.24,-5.965c-8.082,-8.082 -8.082,-20.59 0,-28.48l19.628,-21.937l63.695,-0Z" style="fill:#fff;fill-rule:nonzero;"/>
11
+ <path d="M296.98,229.891l-68.313,-61.386l-65.812,0l74.471,81.206l-74.471,81.206l65.234,-0.192l68.891,-61.193c5.195,-5.581 7.889,-12.701 7.697,-20.013c0.192,-6.735 -2.502,-14.048 -7.697,-19.628Z" style="fill:#fff;fill-rule:nonzero;"/>
12
+ <path d="M215.196,156.382l-54.842,-50.417c-3.849,-3.848 -9.045,-5.965 -14.24,-5.965c-5.196,0 -10.392,2.117 -14.24,5.965c-8.082,8.082 -8.082,20.59 -0,28.48l19.82,21.937l63.502,0Z" style="fill:#fff;fill-rule:nonzero;"/>
13
+ </g>
14
+ </g>
15
+ <defs>
16
+ <linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(3.06162e-14,500,-500,3.06162e-14,267.59,0)"><stop offset="0" style="stop-color:#d8a9ca;stop-opacity:1"/><stop offset="1" style="stop-color:#53519b;stop-opacity:1"/></linearGradient>
17
+ </defs>
18
+ </svg>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="100%" height="100%" viewBox="0 0 679 300" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
4
+ <g>
5
+ <path id="Name" d="M410.6,166.725l19.35,0c0,13.6 -3.4,24.05 -10.2,31.35c-6.8,7.3 -16.4,10.95 -28.8,10.95c-27.3,0 -40.95,-16.05 -40.95,-48.15l0,-9c0,-25.3 7,-41.15 21,-47.55c5.5,-2.6 12.15,-3.9 19.95,-3.9c11.4,0 20.675,3.125 27.825,9.375c7.15,6.25 10.725,15.275 10.725,27.075l-19.5,0c-1.1,-5.9 -3.05,-10.35 -5.85,-13.35c-2.8,-3 -7.2,-4.5 -13.2,-4.5c-7,0 -12.2,2.2 -15.6,6.6c-2.4,3.1 -3.8,8.4 -4.2,15.9c-0.2,2.4 -0.3,5.65 -0.3,9.75l0,9.3c0,11.5 1.6,19.35 4.8,23.55c3.3,4.2 8.425,6.3 15.375,6.3c6.95,0 11.75,-1.925 14.4,-5.775c2.65,-3.85 4.375,-9.825 5.175,-17.925Z" style="fill-rule:nonzero;"/>
6
+ <path d="M464.9,208.125l-19.5,0.15l0,-112.95l19.5,0l0,112.8Z" style="fill-rule:nonzero;"/>
7
+ <path d="M495.8,89.775c4.7,0 7.75,0.725 9.15,2.175c1.4,1.45 2.1,4.5 2.1,9.15c0,4.65 -0.725,7.7 -2.175,9.15c-1.45,1.45 -4.5,2.175 -9.15,2.175c-4.65,0 -7.7,-0.75 -9.15,-2.25c-1.45,-1.5 -2.175,-4.55 -2.175,-9.15c0,-4.6 0.725,-7.625 2.175,-9.075c1.45,-1.45 4.525,-2.175 9.225,-2.175Zm9.6,118.35l-19.5,0l0,-82.5l19.5,0l0,82.5Z" style="fill-rule:nonzero;"/>
8
+ <path d="M570.95,176.775l17.7,-0.15c-0.1,0.8 -0.2,2.25 -0.3,4.35c-0.1,2.1 -0.175,3.525 -0.225,4.275c-0.05,0.75 -0.175,1.925 -0.375,3.525c-0.2,1.6 -0.425,2.775 -0.675,3.525c-0.25,0.75 -0.575,1.725 -0.975,2.925c-1.8,5.2 -6.7,9.3 -14.7,12.3c-5.1,1.8 -10.425,2.7 -15.975,2.7c-5.55,-0 -10.575,-0.9 -15.075,-2.7c-4.5,-1.8 -8.05,-4.1 -10.65,-6.9c-5.9,-6.2 -8.85,-17.825 -8.85,-34.875c0,-17.05 2.95,-28.675 8.85,-34.875c2.6,-2.8 6.15,-5.1 10.65,-6.9c4.5,-1.8 9.5,-2.7 15,-2.7c10.8,0 19,2.7 24.6,8.1c5.6,5.4 8.4,12.9 8.4,22.5l-17.7,0c0,-4.4 -1.1,-7.675 -3.3,-9.825c-2.2,-2.15 -6.275,-3.225 -12.225,-3.225c-5.95,-0 -9.9,1.85 -11.85,5.55c-1.95,3.7 -2.925,9.25 -2.925,16.65l0,7.8c0,11.9 2.3,19.2 6.9,21.9c2.1,1.3 4.85,1.95 8.25,1.95c3.4,-0 6.175,-0.325 8.325,-0.975c2.15,-0.65 3.7,-1.775 4.65,-3.375c0.95,-1.6 1.575,-3.175 1.875,-4.725c0.3,-1.55 0.5,-3.825 0.6,-6.825Z" style="fill-rule:nonzero;"/>
9
+ <path d="M678.65,208.125l-23.4,0l-22.5,-30.3l-8.55,12.15l0,18.15l-19.5,0l0,-112.8l19.5,0l0,71.25l27.3,-40.65l22.05,0l-28.05,38.4l33.15,43.8Z" style="fill-rule:nonzero;"/>
10
+ <g id="Logo">
11
+ <path id="Box" d="M300,30l0,240c0,16.557 -13.443,30 -30,30l-240,-0c-16.557,-0 -30,-13.443 -30,-30l0,-240c0,-16.557 13.443,-30 30,-30l240,0c16.557,0 30,13.443 30,30Z" style="fill:url(#_Linear1);"/>
12
+ <path id="Shadow" d="M300,259.747l0,10.253c0,16.557 -13.443,30 -30,30l-126.946,-0l-63.381,-63.382c2.287,2.184 5.314,3.382 8.342,3.382c3.117,0 6.234,-1.27 8.544,-3.579l32.905,-30.25l-24.131,-0l-7.62,-7.621l39.141,-0.115l41.334,-36.716c3.117,-3.348 4.734,-7.62 4.618,-12.008c0.116,-4.041 -1.501,-8.428 -4.618,-11.776l121.812,121.812Zm-170.882,-165.918l7.274,7.274l-38.102,0l-7.273,-7.274l38.101,0Zm92.367,127.005c5.773,-4.388 2.771,-13.624 -4.619,-13.624l-53.226,-0c-1.963,-0 -3.695,0.693 -5.08,1.963l-19.744,17.665c-5.08,4.618 -1.847,13.162 5.081,13.162l49.185,0c1.616,0 3.233,-0.577 4.503,-1.501l23.9,-17.665Z" style="fill:#493e5e;"/>
13
+ <g id="Icon">
14
+ <path d="M221.485,220.834l-23.9,17.665c-1.27,0.924 -2.887,1.501 -4.503,1.501l-49.185,0c-6.928,0 -10.161,-8.544 -5.081,-13.162l19.744,-17.665c1.385,-1.27 3.117,-1.963 5.08,-1.963l53.226,-0c7.39,-0 10.392,9.236 4.619,13.624Z" style="fill:#fff;fill-rule:nonzero;"/>
15
+ <path d="M129.464,206.171l-32.905,30.25c-2.31,2.309 -5.427,3.579 -8.544,3.579c-3.118,0 -6.235,-1.27 -8.544,-3.579c-4.85,-4.849 -4.85,-12.354 -0,-17.088l11.776,-13.162l38.217,-0Z" style="fill:#fff;fill-rule:nonzero;"/>
16
+ <path d="M178.188,137.935l-40.988,-36.832l-39.487,0l44.683,48.724l-44.683,48.723l39.141,-0.115l41.334,-36.716c3.117,-3.348 4.734,-7.62 4.618,-12.008c0.116,-4.041 -1.501,-8.428 -4.618,-11.776Z" style="fill:#fff;fill-rule:nonzero;"/>
17
+ <path d="M129.118,93.829l-32.906,-30.25c-2.309,-2.309 -5.426,-3.579 -8.544,-3.579c-3.117,0 -6.235,1.27 -8.544,3.579c-4.849,4.849 -4.849,12.354 0,17.088l11.893,13.162l38.101,0Z" style="fill:#fff;fill-rule:nonzero;"/>
18
+ </g>
19
+ </g>
20
+ </g>
21
+ <defs>
22
+ <linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(1.83697e-14,300,-300,1.83697e-14,160.554,0)"><stop offset="0" style="stop-color:#d8a9ca;stop-opacity:1"/><stop offset="1" style="stop-color:#53519b;stop-opacity:1"/></linearGradient>
23
+ </defs>
24
+ </svg>
@@ -3,12 +3,10 @@ Advanced Patterns
3
3
 
4
4
  .. currentmodule:: click
5
5
 
6
- In addition to common functionality that is implemented in the library
7
- itself, there are countless patterns that can be implemented by extending
8
- Click. This page should give some insight into what can be accomplished.
6
+ In addition to common functionality, Click offers some advanced features.
9
7
 
10
8
  .. contents::
11
- :depth: 2
9
+ :depth: 1
12
10
  :local:
13
11
 
14
12
  Callbacks and Eager Options
@@ -110,133 +108,6 @@ also contain the parameter name.
110
108
  println()
111
109
  invoke(roll, input=["42", "2d12"])
112
110
 
113
- .. _custom-groups:
114
-
115
- Custom Groups
116
- -------------
117
-
118
- You can customize the behavior of a group beyond the arguments it accepts by
119
- subclassing :class:`click.Group`.
120
-
121
- The most common methods to override are :meth:`~click.Group.get_command` and
122
- :meth:`~click.Group.list_commands`.
123
-
124
- The following example implements a basic plugin system that loads commands from
125
- Python files in a folder. The command is lazily loaded to avoid slow startup.
126
-
127
- .. code-block:: python
128
-
129
- import importlib.util
130
- import os
131
- import click
132
-
133
- class PluginGroup(click.Group):
134
- def __init__(self, name=None, plugin_folder="commands", **kwargs):
135
- super().__init__(name=name, **kwargs)
136
- self.plugin_folder = plugin_folder
137
-
138
- def list_commands(self, ctx):
139
- rv = []
140
-
141
- for filename in os.listdir(self.plugin_folder):
142
- if filename.endswith(".py"):
143
- rv.append(filename[:-3])
144
-
145
- rv.sort()
146
- return rv
147
-
148
- def get_command(self, ctx, name):
149
- path = os.path.join(self.plugin_folder, f"{name}.py")
150
- spec = importlib.util.spec_from_file_location(name, path)
151
- module = importlib.util.module_from_spec(spec)
152
- spec.loader.exec_module(module)
153
- return module.cli
154
-
155
- cli = PluginGroup(
156
- plugin_folder=os.path.join(os.path.dirname(__file__), "commands")
157
- )
158
-
159
- if __name__ == "__main__":
160
- cli()
161
-
162
- Custom classes can also be used with decorators:
163
-
164
- .. code-block:: python
165
-
166
- @click.group(
167
- cls=PluginGroup,
168
- plugin_folder=os.path.join(os.path.dirname(__file__), "commands")
169
- )
170
- def cli():
171
- pass
172
-
173
- .. _aliases:
174
-
175
- Command Aliases
176
- ---------------
177
-
178
- Many tools support aliases for commands. For example, you can configure
179
- ``git`` to accept ``git ci`` as alias for ``git commit``. Other tools also
180
- support auto-discovery for aliases by automatically shortening them.
181
-
182
- It's possible to customize :class:`Group` to provide this functionality. As
183
- explained in :ref:`custom-groups`, a group provides two methods:
184
- :meth:`~Group.list_commands` and :meth:`~Group.get_command`. In this particular
185
- case, you only need to override the latter as you generally don't want to
186
- enumerate the aliases on the help page in order to avoid confusion.
187
-
188
- The following example implements a subclass of :class:`Group` that accepts a
189
- prefix for a command. If there was a command called ``push``, it would accept
190
- ``pus`` as an alias (so long as it was unique):
191
-
192
- .. click:example::
193
-
194
- class AliasedGroup(click.Group):
195
- def get_command(self, ctx, cmd_name):
196
- rv = super().get_command(ctx, cmd_name)
197
-
198
- if rv is not None:
199
- return rv
200
-
201
- matches = [
202
- x for x in self.list_commands(ctx)
203
- if x.startswith(cmd_name)
204
- ]
205
-
206
- if not matches:
207
- return None
208
-
209
- if len(matches) == 1:
210
- return click.Group.get_command(self, ctx, matches[0])
211
-
212
- ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
213
-
214
- def resolve_command(self, ctx, args):
215
- # always return the full command name
216
- _, cmd, args = super().resolve_command(ctx, args)
217
- return cmd.name, cmd, args
218
-
219
- It can be used like this:
220
-
221
- .. click:example::
222
-
223
- @click.group(cls=AliasedGroup)
224
- def cli():
225
- pass
226
-
227
- @cli.command
228
- def push():
229
- pass
230
-
231
- @cli.command
232
- def pop():
233
- pass
234
-
235
- See the `alias example`_ in Click's repository for another example.
236
-
237
- .. _alias example: https://github.com/pallets/click/tree/main/examples/aliases
238
-
239
-
240
111
  Parameter Modifications
241
112
  -----------------------
242
113
 
@@ -360,64 +231,6 @@ And what it looks like:
360
231
  invoke(cli, prog_name='cli', args=['dist'])
361
232
 
362
233
 
363
- .. _callback-evaluation-order:
364
-
365
- Callback Evaluation Order
366
- -------------------------
367
-
368
- Click works a bit differently than some other command line parsers in that
369
- it attempts to reconcile the order of arguments as defined by the
370
- programmer with the order of arguments as defined by the user before
371
- invoking any callbacks.
372
-
373
- This is an important concept to understand when porting complex
374
- patterns to Click from optparse or other systems. A parameter
375
- callback invocation in optparse happens as part of the parsing step,
376
- whereas a callback invocation in Click happens after the parsing.
377
-
378
- The main difference is that in optparse, callbacks are invoked with the raw
379
- value as it happens, whereas a callback in Click is invoked after the
380
- value has been fully converted.
381
-
382
- Generally, the order of invocation is driven by the order in which the user
383
- provides the arguments to the script; if there is an option called ``--foo``
384
- and an option called ``--bar`` and the user calls it as ``--bar
385
- --foo``, then the callback for ``bar`` will fire before the one for ``foo``.
386
-
387
- There are three exceptions to this rule which are important to know:
388
-
389
- Eagerness:
390
- An option can be set to be "eager". All eager parameters are
391
- evaluated before all non-eager parameters, but again in the order as
392
- they were provided on the command line by the user.
393
-
394
- This is important for parameters that execute and exit like ``--help``
395
- and ``--version``. Both are eager parameters, but whatever parameter
396
- comes first on the command line will win and exit the program.
397
-
398
- Repeated parameters:
399
- If an option or argument is split up on the command line into multiple
400
- places because it is repeated -- for instance, ``--exclude foo --include
401
- baz --exclude bar`` -- the callback will fire based on the position of
402
- the first option. In this case, the callback will fire for
403
- ``exclude`` and it will be passed both options (``foo`` and
404
- ``bar``), then the callback for ``include`` will fire with ``baz``
405
- only.
406
-
407
- Note that even if a parameter does not allow multiple versions, Click
408
- will still accept the position of the first, but it will ignore every
409
- value except the last. The reason for this is to allow composability
410
- through shell aliases that set defaults.
411
-
412
- Missing parameters:
413
- If a parameter is not defined on the command line, the callback will
414
- still fire. This is different from how it works in optparse where
415
- undefined values do not fire the callback. Missing parameters fire
416
- their callbacks at the very end which makes it possible for them to
417
- default to values from a parameter that came before.
418
-
419
- Most of the time you do not need to be concerned about any of this,
420
- but it is important to know how it works for some advanced cases.
421
234
 
422
235
  .. _forwarding-unknown-options:
423
236
 
@@ -515,74 +328,6 @@ everything below a subcommand be forwarded to another application than to
515
328
  handle some arguments yourself.
516
329
 
517
330
 
518
- Global Context Access
519
- ---------------------
520
-
521
- .. versionadded:: 5.0
522
-
523
- Starting with Click 5.0 it is possible to access the current context from
524
- anywhere within the same thread through the use of the
525
- :func:`get_current_context` function which returns it. This is primarily
526
- useful for accessing the context bound object as well as some flags that
527
- are stored on it to customize the runtime behavior. For instance the
528
- :func:`echo` function does this to infer the default value of the `color`
529
- flag.
530
-
531
- Example usage::
532
-
533
- def get_current_command_name():
534
- return click.get_current_context().info_name
535
-
536
- It should be noted that this only works within the current thread. If you
537
- spawn additional threads then those threads will not have the ability to
538
- refer to the current context. If you want to give another thread the
539
- ability to refer to this context you need to use the context within the
540
- thread as a context manager::
541
-
542
- def spawn_thread(ctx, func):
543
- def wrapper():
544
- with ctx:
545
- func()
546
- t = threading.Thread(target=wrapper)
547
- t.start()
548
- return t
549
-
550
- Now the thread function can access the context like the main thread would
551
- do. However if you do use this for threading you need to be very careful
552
- as the vast majority of the context is not thread safe! You are only
553
- allowed to read from the context, but not to perform any modifications on
554
- it.
555
-
556
-
557
- Detecting the Source of a Parameter
558
- -----------------------------------
559
-
560
- In some situations it's helpful to understand whether or not an option
561
- or parameter came from the command line, the environment, the default
562
- value, or :attr:`Context.default_map`. The
563
- :meth:`Context.get_parameter_source` method can be used to find this
564
- out. It will return a member of the :class:`~click.core.ParameterSource`
565
- enum.
566
-
567
- .. click:example::
568
-
569
- @click.command()
570
- @click.argument('port', nargs=1, default=8080, envvar="PORT")
571
- @click.pass_context
572
- def cli(ctx, port):
573
- source = ctx.get_parameter_source("port")
574
- click.echo(f"Port came from {source.name}")
575
-
576
- .. click:run::
577
-
578
- invoke(cli, prog_name='cli', args=['8080'])
579
- println()
580
- invoke(cli, prog_name='cli', args=[], env={"PORT": "8080"})
581
- println()
582
- invoke(cli, prog_name='cli', args=[])
583
- println()
584
-
585
-
586
331
  Managing Resources
587
332
  ------------------
588
333
 
@@ -0,0 +1,67 @@
1
+ Click Concepts
2
+ ================
3
+
4
+ This section covers concepts about Click's design.
5
+
6
+ .. contents::
7
+ :depth: 1
8
+ :local:
9
+
10
+ .. _callback-evaluation-order:
11
+
12
+ Callback Evaluation Order
13
+ -------------------------
14
+
15
+ Click works a bit differently than some other command line parsers in that
16
+ it attempts to reconcile the order of arguments as defined by the
17
+ programmer with the order of arguments as defined by the user before
18
+ invoking any callbacks.
19
+
20
+ This is an important concept to understand when porting complex
21
+ patterns to Click from optparse or other systems. A parameter
22
+ callback invocation in optparse happens as part of the parsing step,
23
+ whereas a callback invocation in Click happens after the parsing.
24
+
25
+ The main difference is that in optparse, callbacks are invoked with the raw
26
+ value as it happens, whereas a callback in Click is invoked after the
27
+ value has been fully converted.
28
+
29
+ Generally, the order of invocation is driven by the order in which the user
30
+ provides the arguments to the script; if there is an option called ``--foo``
31
+ and an option called ``--bar`` and the user calls it as ``--bar
32
+ --foo``, then the callback for ``bar`` will fire before the one for ``foo``.
33
+
34
+ There are three exceptions to this rule which are important to know:
35
+
36
+ Eagerness:
37
+ An option can be set to be "eager". All eager parameters are
38
+ evaluated before all non-eager parameters, but again in the order as
39
+ they were provided on the command line by the user.
40
+
41
+ This is important for parameters that execute and exit like ``--help``
42
+ and ``--version``. Both are eager parameters, but whatever parameter
43
+ comes first on the command line will win and exit the program.
44
+
45
+ Repeated parameters:
46
+ If an option or argument is split up on the command line into multiple
47
+ places because it is repeated -- for instance, ``--exclude foo --include
48
+ baz --exclude bar`` -- the callback will fire based on the position of
49
+ the first option. In this case, the callback will fire for
50
+ ``exclude`` and it will be passed both options (``foo`` and
51
+ ``bar``), then the callback for ``include`` will fire with ``baz``
52
+ only.
53
+
54
+ Note that even if a parameter does not allow multiple versions, Click
55
+ will still accept the position of the first, but it will ignore every
56
+ value except the last. The reason for this is to allow composability
57
+ through shell aliases that set defaults.
58
+
59
+ Missing parameters:
60
+ If a parameter is not defined on the command line, the callback will
61
+ still fire. This is different from how it works in optparse where
62
+ undefined values do not fire the callback. Missing parameters fire
63
+ their callbacks at the very end which makes it possible for them to
64
+ default to values from a parameter that came before.
65
+
66
+ Most of the time you do not need to be concerned about any of this,
67
+ but it is important to know how it works for some advanced cases.
@@ -6,11 +6,14 @@ Basic Commands, Groups, Context
6
6
  Commands and Groups are the building blocks for Click applications. :class:`Command` wraps a function to make it into a cli command. :class:`Group` wraps Commands and Groups to make them into applications. :class:`Context` is how groups and commands communicate.
7
7
 
8
8
  .. contents::
9
- :depth: 1
9
+ :depth: 2
10
10
  :local:
11
11
 
12
+ Commands
13
+ --------------------
14
+
12
15
  Basic Command Example
13
- ----------------------
16
+ ^^^^^^^^^^^^^^^^^^^^^^^
14
17
  A simple command decorator takes no arguments.
15
18
 
16
19
  .. click:example::
@@ -24,7 +27,7 @@ A simple command decorator takes no arguments.
24
27
  invoke(hello, args=['--count', '2',])
25
28
 
26
29
  Renaming Commands
27
- ------------------
30
+ ^^^^^^^^^^^^^^^^^^^
28
31
  By default the command is the function name with underscores replaced by dashes. To change this pass the desired name into the first positional argument.
29
32
 
30
33
  .. click:example::
@@ -38,7 +41,7 @@ By default the command is the function name with underscores replaced by dashes.
38
41
  invoke(hello, args=['--count', '2',])
39
42
 
40
43
  Deprecating Commands
41
- ---------------------
44
+ ^^^^^^^^^^^^^^^^^^^^^^
42
45
  To mark a command as deprecated pass in ``deprecated=True``
43
46
 
44
47
  .. click:example::
@@ -51,8 +54,11 @@ To mark a command as deprecated pass in ``deprecated=True``
51
54
  .. click:run::
52
55
  invoke(hello, args=['--count', '2',])
53
56
 
57
+ Groups
58
+ ------------
59
+
54
60
  Basic Group Example
55
- ---------------------
61
+ ^^^^^^^^^^^^^^^^^^^^^
56
62
  A group wraps one or more commands. After being wrapped, the commands are nested under that group. You can see that on the help pages and in the execution. By default, invoking the group with no command shows the help page.
57
63
 
58
64
  .. click:example::
@@ -82,7 +88,7 @@ At the command level:
82
88
  As you can see from the above example, the function wrapped by the group decorator executes unless it is interrupted (for example by calling the help).
83
89
 
84
90
  Renaming Groups
85
- -----------------
91
+ ^^^^^^^^^^^^^^^^^
86
92
  To have a name other than the decorated function name as the group name, pass it in as the first positional argument.
87
93
 
88
94
  .. click:example::
@@ -101,7 +107,7 @@ To have a name other than the decorated function name as the group name, pass it
101
107
  invoke(greeting, args=['say-hello'])
102
108
 
103
109
  Group Invocation Without Command
104
- --------------------------------
110
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105
111
 
106
112
  By default, if a group is passed without a command, the group is not invoked and a command automatically passes ``--help``. To change this, pass ``invoke_without_command=True`` to the group. The context object also includes information about whether or not the group invocation would go to a command nested under it.
107
113
 
@@ -127,7 +133,7 @@ By default, if a group is passed without a command, the group is not invoked and
127
133
 
128
134
 
129
135
  Group Separation
130
- --------------------------
136
+ ^^^^^^^^^^^^^^^^^^^
131
137
  Command :ref:`parameters` attached to a command belong only to that command.
132
138
 
133
139
  .. click:example::
@@ -162,7 +168,7 @@ This behavior is observable with the ``--help`` option. Suppose we have a group
162
168
  - But ``tool --help sub`` treats ``--help`` as an argument for the main program. Click then invokes the callback for ``--help``, which prints the help and aborts the program before click can process the subcommand.
163
169
 
164
170
  Arbitrary Nesting
165
- ------------------
171
+ ^^^^^^^^^^^^^^^^^^^
166
172
  :class:`Commands <Command>` are attached to a :class:`Group`. Multiple groups can be attached to another group. Groups containing multiple groups can be attached to a group, and so on. To invoke a command nested under multiple groups, all the groups under which it is nested must be invoked.
167
173
 
168
174
  .. click:example::
@@ -189,7 +195,7 @@ Arbitrary Nesting
189
195
  invoke(cli, args=['session', 'initdb'])
190
196
 
191
197
  Lazily Attaching Commands
192
- --------------------------
198
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
193
199
  Most examples so far have attached the commands to a group immediately, but commands may be registered later. This could be used to split commands into multiple Python modules. Regardless of how they are attached, the commands are invoked identically.
194
200
 
195
201
  .. click:example::
@@ -218,7 +224,7 @@ Context Object
218
224
  The :class:`Context` object is how commands and groups communicate.
219
225
 
220
226
  Auto Envvar Prefix
221
- --------------------
227
+ ^^^^^^^^^^^^^^^^^^^^
222
228
  Automatically built environment variables are supported for options only. To enable this feature, the ``auto_envvar_prefix`` parameter needs to be passed to the script that is invoked. Each command and parameter is then added as an uppercase underscore-separated variable. If you have a subcommand
223
229
  called ``run`` taking an option called ``reload`` and the prefix is ``WEB``, then the variable is ``WEB_RUN_RELOAD``.
224
230
 
@@ -267,3 +273,70 @@ the prefix is ``WEB``, then the variable is ``WEB_RUN_SERVER_HOST``.
267
273
  invoke(cli, args=['greet',],
268
274
  env={'GREETER_GREET_USERNAME': 'John', 'GREETER_DEBUG': 'false'},
269
275
  auto_envvar_prefix='GREETER')
276
+
277
+ Global Context Access
278
+ ^^^^^^^^^^^^^^^^^^^^^^
279
+
280
+ .. versionadded:: 5.0
281
+
282
+ Starting with Click 5.0 it is possible to access the current context from
283
+ anywhere within the same thread through the use of the
284
+ :func:`get_current_context` function which returns it. This is primarily
285
+ useful for accessing the context bound object as well as some flags that
286
+ are stored on it to customize the runtime behavior. For instance the
287
+ :func:`echo` function does this to infer the default value of the `color`
288
+ flag.
289
+
290
+ Example usage::
291
+
292
+ def get_current_command_name():
293
+ return click.get_current_context().info_name
294
+
295
+ It should be noted that this only works within the current thread. If you
296
+ spawn additional threads then those threads will not have the ability to
297
+ refer to the current context. If you want to give another thread the
298
+ ability to refer to this context you need to use the context within the
299
+ thread as a context manager::
300
+
301
+ def spawn_thread(ctx, func):
302
+ def wrapper():
303
+ with ctx:
304
+ func()
305
+ t = threading.Thread(target=wrapper)
306
+ t.start()
307
+ return t
308
+
309
+ Now the thread function can access the context like the main thread would
310
+ do. However if you do use this for threading you need to be very careful
311
+ as the vast majority of the context is not thread safe! You are only
312
+ allowed to read from the context, but not to perform any modifications on
313
+ it.
314
+
315
+
316
+ Detecting the Source of a Parameter
317
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
318
+
319
+ In some situations it's helpful to understand whether or not an option
320
+ or parameter came from the command line, the environment, the default
321
+ value, or :attr:`Context.default_map`. The
322
+ :meth:`Context.get_parameter_source` method can be used to find this
323
+ out. It will return a member of the :class:`~click.core.ParameterSource`
324
+ enum.
325
+
326
+ .. click:example::
327
+
328
+ @click.command()
329
+ @click.argument('port', nargs=1, default=8080, envvar="PORT")
330
+ @click.pass_context
331
+ def cli(ctx, port):
332
+ source = ctx.get_parameter_source("port")
333
+ click.echo(f"Port came from {source.name}")
334
+
335
+ .. click:run::
336
+
337
+ invoke(cli, prog_name='cli', args=['8080'])
338
+ println()
339
+ invoke(cli, prog_name='cli', args=[], env={"PORT": "8080"})
340
+ println()
341
+ invoke(cli, prog_name='cli', args=[])
342
+ println()
@@ -16,6 +16,10 @@ In a theoretical world of two separate Click command line utilities, they
16
16
  could solve this problem by nesting one inside the other. For instance, the
17
17
  web framework could also load the commands for the message queue framework.
18
18
 
19
+ .. contents::
20
+ :depth: 1
21
+ :local:
22
+
19
23
  Basic Concepts
20
24
  --------------
21
25