rigid 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/rigid +4 -0
- data/rigid +16 -0
- data/vendor/PyYAML-3.12.dist-info/DESCRIPTION.rst +12 -0
- data/vendor/PyYAML-3.12.dist-info/INSTALLER +1 -0
- data/vendor/PyYAML-3.12.dist-info/METADATA +35 -0
- data/vendor/PyYAML-3.12.dist-info/RECORD +42 -0
- data/vendor/PyYAML-3.12.dist-info/WHEEL +5 -0
- data/vendor/PyYAML-3.12.dist-info/metadata.json +1 -0
- data/vendor/PyYAML-3.12.dist-info/top_level.txt +2 -0
- data/vendor/_yaml.so +0 -0
- data/vendor/click/__init__.py +98 -0
- data/vendor/click/__init__.pyc +0 -0
- data/vendor/click/_bashcomplete.py +83 -0
- data/vendor/click/_bashcomplete.pyc +0 -0
- data/vendor/click/_compat.py +642 -0
- data/vendor/click/_compat.pyc +0 -0
- data/vendor/click/_termui_impl.py +547 -0
- data/vendor/click/_termui_impl.pyc +0 -0
- data/vendor/click/_textwrap.py +38 -0
- data/vendor/click/_textwrap.pyc +0 -0
- data/vendor/click/_unicodefun.py +119 -0
- data/vendor/click/_unicodefun.pyc +0 -0
- data/vendor/click/_winconsole.py +273 -0
- data/vendor/click/_winconsole.pyc +0 -0
- data/vendor/click/core.py +1738 -0
- data/vendor/click/core.pyc +0 -0
- data/vendor/click/decorators.py +304 -0
- data/vendor/click/decorators.pyc +0 -0
- data/vendor/click/exceptions.py +201 -0
- data/vendor/click/exceptions.pyc +0 -0
- data/vendor/click/formatting.py +256 -0
- data/vendor/click/formatting.pyc +0 -0
- data/vendor/click/globals.py +48 -0
- data/vendor/click/globals.pyc +0 -0
- data/vendor/click/parser.py +426 -0
- data/vendor/click/parser.pyc +0 -0
- data/vendor/click/termui.py +539 -0
- data/vendor/click/termui.pyc +0 -0
- data/vendor/click/testing.py +322 -0
- data/vendor/click/testing.pyc +0 -0
- data/vendor/click/types.py +550 -0
- data/vendor/click/types.pyc +0 -0
- data/vendor/click/utils.py +415 -0
- data/vendor/click/utils.pyc +0 -0
- data/vendor/click-6.6.dist-info/DESCRIPTION.rst +3 -0
- data/vendor/click-6.6.dist-info/INSTALLER +1 -0
- data/vendor/click-6.6.dist-info/METADATA +16 -0
- data/vendor/click-6.6.dist-info/RECORD +41 -0
- data/vendor/click-6.6.dist-info/WHEEL +6 -0
- data/vendor/click-6.6.dist-info/metadata.json +1 -0
- data/vendor/click-6.6.dist-info/top_level.txt +1 -0
- data/vendor/easy_install.py +5 -0
- data/vendor/easy_install.pyc +0 -0
- data/vendor/pip-9.0.1.dist-info/DESCRIPTION.rst +39 -0
- data/vendor/pip-9.0.1.dist-info/INSTALLER +1 -0
- data/vendor/pip-9.0.1.dist-info/METADATA +69 -0
- data/vendor/pip-9.0.1.dist-info/RECORD +501 -0
- data/vendor/pip-9.0.1.dist-info/WHEEL +6 -0
- data/vendor/pip-9.0.1.dist-info/entry_points.txt +5 -0
- data/vendor/pip-9.0.1.dist-info/metadata.json +1 -0
- data/vendor/pip-9.0.1.dist-info/top_level.txt +1 -0
- data/vendor/pkg_resources/__init__.py +3051 -0
- data/vendor/pkg_resources/__init__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/__init__.py +0 -0
- data/vendor/pkg_resources/_vendor/__init__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/appdirs.py +552 -0
- data/vendor/pkg_resources/_vendor/appdirs.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/__about__.py +21 -0
- data/vendor/pkg_resources/_vendor/packaging/__about__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/__init__.py +14 -0
- data/vendor/pkg_resources/_vendor/packaging/__init__.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/_compat.py +30 -0
- data/vendor/pkg_resources/_vendor/packaging/_compat.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/_structures.py +68 -0
- data/vendor/pkg_resources/_vendor/packaging/_structures.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/markers.py +287 -0
- data/vendor/pkg_resources/_vendor/packaging/markers.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/requirements.py +127 -0
- data/vendor/pkg_resources/_vendor/packaging/requirements.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/specifiers.py +774 -0
- data/vendor/pkg_resources/_vendor/packaging/specifiers.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/utils.py +14 -0
- data/vendor/pkg_resources/_vendor/packaging/utils.pyc +0 -0
- data/vendor/pkg_resources/_vendor/packaging/version.py +393 -0
- data/vendor/pkg_resources/_vendor/packaging/version.pyc +0 -0
- data/vendor/pkg_resources/_vendor/pyparsing.py +5696 -0
- data/vendor/pkg_resources/_vendor/pyparsing.pyc +0 -0
- data/vendor/pkg_resources/_vendor/six.py +868 -0
- data/vendor/pkg_resources/_vendor/six.pyc +0 -0
- data/vendor/pkg_resources/extern/__init__.py +73 -0
- data/vendor/pkg_resources/extern/__init__.pyc +0 -0
- data/vendor/requests/__init__.py +86 -0
- data/vendor/requests/__init__.pyc +0 -0
- data/vendor/requests/adapters.py +503 -0
- data/vendor/requests/adapters.pyc +0 -0
- data/vendor/requests/api.py +148 -0
- data/vendor/requests/api.pyc +0 -0
- data/vendor/requests/auth.py +252 -0
- data/vendor/requests/auth.pyc +0 -0
- data/vendor/requests/cacert.pem +5616 -0
- data/vendor/requests/certs.py +25 -0
- data/vendor/requests/certs.pyc +0 -0
- data/vendor/requests/compat.py +66 -0
- data/vendor/requests/compat.pyc +0 -0
- data/vendor/requests/cookies.py +540 -0
- data/vendor/requests/cookies.pyc +0 -0
- data/vendor/requests/exceptions.py +114 -0
- data/vendor/requests/exceptions.pyc +0 -0
- data/vendor/requests/hooks.py +34 -0
- data/vendor/requests/hooks.pyc +0 -0
- data/vendor/requests/models.py +873 -0
- data/vendor/requests/models.pyc +0 -0
- data/vendor/requests/packages/__init__.py +36 -0
- data/vendor/requests/packages/__init__.pyc +0 -0
- data/vendor/requests/packages/chardet/__init__.py +32 -0
- data/vendor/requests/packages/chardet/__init__.pyc +0 -0
- data/vendor/requests/packages/chardet/big5freq.py +925 -0
- data/vendor/requests/packages/chardet/big5freq.pyc +0 -0
- data/vendor/requests/packages/chardet/big5prober.py +42 -0
- data/vendor/requests/packages/chardet/big5prober.pyc +0 -0
- data/vendor/requests/packages/chardet/chardetect.py +80 -0
- data/vendor/requests/packages/chardet/chardetect.pyc +0 -0
- data/vendor/requests/packages/chardet/chardistribution.py +231 -0
- data/vendor/requests/packages/chardet/chardistribution.pyc +0 -0
- data/vendor/requests/packages/chardet/charsetgroupprober.py +106 -0
- data/vendor/requests/packages/chardet/charsetgroupprober.pyc +0 -0
- data/vendor/requests/packages/chardet/charsetprober.py +62 -0
- data/vendor/requests/packages/chardet/charsetprober.pyc +0 -0
- data/vendor/requests/packages/chardet/codingstatemachine.py +61 -0
- data/vendor/requests/packages/chardet/codingstatemachine.pyc +0 -0
- data/vendor/requests/packages/chardet/compat.py +34 -0
- data/vendor/requests/packages/chardet/compat.pyc +0 -0
- data/vendor/requests/packages/chardet/constants.py +39 -0
- data/vendor/requests/packages/chardet/constants.pyc +0 -0
- data/vendor/requests/packages/chardet/cp949prober.py +44 -0
- data/vendor/requests/packages/chardet/cp949prober.pyc +0 -0
- data/vendor/requests/packages/chardet/escprober.py +86 -0
- data/vendor/requests/packages/chardet/escprober.pyc +0 -0
- data/vendor/requests/packages/chardet/escsm.py +242 -0
- data/vendor/requests/packages/chardet/escsm.pyc +0 -0
- data/vendor/requests/packages/chardet/eucjpprober.py +90 -0
- data/vendor/requests/packages/chardet/eucjpprober.pyc +0 -0
- data/vendor/requests/packages/chardet/euckrfreq.py +596 -0
- data/vendor/requests/packages/chardet/euckrfreq.pyc +0 -0
- data/vendor/requests/packages/chardet/euckrprober.py +42 -0
- data/vendor/requests/packages/chardet/euckrprober.pyc +0 -0
- data/vendor/requests/packages/chardet/euctwfreq.py +428 -0
- data/vendor/requests/packages/chardet/euctwfreq.pyc +0 -0
- data/vendor/requests/packages/chardet/euctwprober.py +41 -0
- data/vendor/requests/packages/chardet/euctwprober.pyc +0 -0
- data/vendor/requests/packages/chardet/gb2312freq.py +472 -0
- data/vendor/requests/packages/chardet/gb2312freq.pyc +0 -0
- data/vendor/requests/packages/chardet/gb2312prober.py +41 -0
- data/vendor/requests/packages/chardet/gb2312prober.pyc +0 -0
- data/vendor/requests/packages/chardet/hebrewprober.py +283 -0
- data/vendor/requests/packages/chardet/hebrewprober.pyc +0 -0
- data/vendor/requests/packages/chardet/jisfreq.py +569 -0
- data/vendor/requests/packages/chardet/jisfreq.pyc +0 -0
- data/vendor/requests/packages/chardet/jpcntx.py +227 -0
- data/vendor/requests/packages/chardet/jpcntx.pyc +0 -0
- data/vendor/requests/packages/chardet/langbulgarianmodel.py +229 -0
- data/vendor/requests/packages/chardet/langbulgarianmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langcyrillicmodel.py +329 -0
- data/vendor/requests/packages/chardet/langcyrillicmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langgreekmodel.py +225 -0
- data/vendor/requests/packages/chardet/langgreekmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langhebrewmodel.py +201 -0
- data/vendor/requests/packages/chardet/langhebrewmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langhungarianmodel.py +225 -0
- data/vendor/requests/packages/chardet/langhungarianmodel.pyc +0 -0
- data/vendor/requests/packages/chardet/langthaimodel.py +200 -0
- data/vendor/requests/packages/chardet/langthaimodel.pyc +0 -0
- data/vendor/requests/packages/chardet/latin1prober.py +139 -0
- data/vendor/requests/packages/chardet/latin1prober.pyc +0 -0
- data/vendor/requests/packages/chardet/mbcharsetprober.py +86 -0
- data/vendor/requests/packages/chardet/mbcharsetprober.pyc +0 -0
- data/vendor/requests/packages/chardet/mbcsgroupprober.py +54 -0
- data/vendor/requests/packages/chardet/mbcsgroupprober.pyc +0 -0
- data/vendor/requests/packages/chardet/mbcssm.py +572 -0
- data/vendor/requests/packages/chardet/mbcssm.pyc +0 -0
- data/vendor/requests/packages/chardet/sbcharsetprober.py +120 -0
- data/vendor/requests/packages/chardet/sbcharsetprober.pyc +0 -0
- data/vendor/requests/packages/chardet/sbcsgroupprober.py +69 -0
- data/vendor/requests/packages/chardet/sbcsgroupprober.pyc +0 -0
- data/vendor/requests/packages/chardet/sjisprober.py +91 -0
- data/vendor/requests/packages/chardet/sjisprober.pyc +0 -0
- data/vendor/requests/packages/chardet/universaldetector.py +170 -0
- data/vendor/requests/packages/chardet/universaldetector.pyc +0 -0
- data/vendor/requests/packages/chardet/utf8prober.py +76 -0
- data/vendor/requests/packages/chardet/utf8prober.pyc +0 -0
- data/vendor/requests/packages/urllib3/__init__.py +96 -0
- data/vendor/requests/packages/urllib3/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/_collections.py +324 -0
- data/vendor/requests/packages/urllib3/_collections.pyc +0 -0
- data/vendor/requests/packages/urllib3/connection.py +330 -0
- data/vendor/requests/packages/urllib3/connection.pyc +0 -0
- data/vendor/requests/packages/urllib3/connectionpool.py +866 -0
- data/vendor/requests/packages/urllib3/connectionpool.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/__init__.py +0 -0
- data/vendor/requests/packages/urllib3/contrib/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/appengine.py +231 -0
- data/vendor/requests/packages/urllib3/contrib/appengine.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/ntlmpool.py +115 -0
- data/vendor/requests/packages/urllib3/contrib/ntlmpool.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/pyopenssl.py +358 -0
- data/vendor/requests/packages/urllib3/contrib/pyopenssl.pyc +0 -0
- data/vendor/requests/packages/urllib3/contrib/socks.py +172 -0
- data/vendor/requests/packages/urllib3/contrib/socks.pyc +0 -0
- data/vendor/requests/packages/urllib3/exceptions.py +209 -0
- data/vendor/requests/packages/urllib3/exceptions.pyc +0 -0
- data/vendor/requests/packages/urllib3/fields.py +178 -0
- data/vendor/requests/packages/urllib3/fields.pyc +0 -0
- data/vendor/requests/packages/urllib3/filepost.py +94 -0
- data/vendor/requests/packages/urllib3/filepost.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/__init__.py +5 -0
- data/vendor/requests/packages/urllib3/packages/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/ordered_dict.py +259 -0
- data/vendor/requests/packages/urllib3/packages/ordered_dict.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/six.py +868 -0
- data/vendor/requests/packages/urllib3/packages/six.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py +13 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py +105 -0
- data/vendor/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.pyc +0 -0
- data/vendor/requests/packages/urllib3/poolmanager.py +367 -0
- data/vendor/requests/packages/urllib3/poolmanager.pyc +0 -0
- data/vendor/requests/packages/urllib3/request.py +151 -0
- data/vendor/requests/packages/urllib3/request.pyc +0 -0
- data/vendor/requests/packages/urllib3/response.py +530 -0
- data/vendor/requests/packages/urllib3/response.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/__init__.py +46 -0
- data/vendor/requests/packages/urllib3/util/__init__.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/connection.py +144 -0
- data/vendor/requests/packages/urllib3/util/connection.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/request.py +72 -0
- data/vendor/requests/packages/urllib3/util/request.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/response.py +74 -0
- data/vendor/requests/packages/urllib3/util/response.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/retry.py +300 -0
- data/vendor/requests/packages/urllib3/util/retry.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/ssl_.py +320 -0
- data/vendor/requests/packages/urllib3/util/ssl_.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/timeout.py +242 -0
- data/vendor/requests/packages/urllib3/util/timeout.pyc +0 -0
- data/vendor/requests/packages/urllib3/util/url.py +217 -0
- data/vendor/requests/packages/urllib3/util/url.pyc +0 -0
- data/vendor/requests/sessions.py +712 -0
- data/vendor/requests/sessions.pyc +0 -0
- data/vendor/requests/status_codes.py +91 -0
- data/vendor/requests/status_codes.pyc +0 -0
- data/vendor/requests/structures.py +105 -0
- data/vendor/requests/structures.pyc +0 -0
- data/vendor/requests/utils.py +817 -0
- data/vendor/requests/utils.pyc +0 -0
- data/vendor/requests-2.11.1.dist-info/DESCRIPTION.rst +1294 -0
- data/vendor/requests-2.11.1.dist-info/INSTALLER +1 -0
- data/vendor/requests-2.11.1.dist-info/METADATA +1323 -0
- data/vendor/requests-2.11.1.dist-info/RECORD +170 -0
- data/vendor/requests-2.11.1.dist-info/WHEEL +6 -0
- data/vendor/requests-2.11.1.dist-info/metadata.json +1 -0
- data/vendor/requests-2.11.1.dist-info/top_level.txt +1 -0
- data/vendor/rigid/__init__.py +1 -0
- data/vendor/rigid/__init__.pyc +0 -0
- data/vendor/rigid/api.py +129 -0
- data/vendor/rigid/api.pyc +0 -0
- data/vendor/rigid/commands/__init__.py +260 -0
- data/vendor/rigid/commands/__init__.pyc +0 -0
- data/vendor/rigid/commands/deploy.py +0 -0
- data/vendor/rigid/commands/deploy.pyc +0 -0
- data/vendor/rigid/deploy.py +70 -0
- data/vendor/rigid/deploy.pyc +0 -0
- data/vendor/rigid/file_scanner.py +63 -0
- data/vendor/rigid/file_scanner.pyc +0 -0
- data/vendor/rigid/utils.py +17 -0
- data/vendor/rigid/utils.pyc +0 -0
- data/vendor/rigid-0.2.0.dist-info/DESCRIPTION.rst +3 -0
- data/vendor/rigid-0.2.0.dist-info/INSTALLER +1 -0
- data/vendor/rigid-0.2.0.dist-info/METADATA +23 -0
- data/vendor/rigid-0.2.0.dist-info/RECORD +49 -0
- data/vendor/rigid-0.2.0.dist-info/WHEEL +5 -0
- data/vendor/rigid-0.2.0.dist-info/entry_points.txt +3 -0
- data/vendor/rigid-0.2.0.dist-info/metadata.json +1 -0
- data/vendor/rigid-0.2.0.dist-info/top_level.txt +2 -0
- data/vendor/setuptools-28.8.0.dist-info/DESCRIPTION.rst +243 -0
- data/vendor/setuptools-28.8.0.dist-info/INSTALLER +1 -0
- data/vendor/setuptools-28.8.0.dist-info/METADATA +272 -0
- data/vendor/setuptools-28.8.0.dist-info/RECORD +143 -0
- data/vendor/setuptools-28.8.0.dist-info/WHEEL +6 -0
- data/vendor/setuptools-28.8.0.dist-info/dependency_links.txt +2 -0
- data/vendor/setuptools-28.8.0.dist-info/entry_points.txt +63 -0
- data/vendor/setuptools-28.8.0.dist-info/metadata.json +1 -0
- data/vendor/setuptools-28.8.0.dist-info/top_level.txt +3 -0
- data/vendor/setuptools-28.8.0.dist-info/zip-safe +1 -0
- data/vendor/tests/__init__.py +0 -0
- data/vendor/tests/__init__.pyc +0 -0
- data/vendor/tests/integration/__init__.py +0 -0
- data/vendor/tests/integration/__init__.pyc +0 -0
- data/vendor/tests/integration/test_app.py +63 -0
- data/vendor/tests/integration/test_app.pyc +0 -0
- data/vendor/tests/integration/test_apps.py +27 -0
- data/vendor/tests/integration/test_apps.pyc +0 -0
- data/vendor/tests/integration/test_deploy.py +128 -0
- data/vendor/tests/integration/test_deploy.pyc +0 -0
- data/vendor/tests/integration/test_domains.py +35 -0
- data/vendor/tests/integration/test_domains.pyc +0 -0
- data/vendor/tests/integration/test_login.py +37 -0
- data/vendor/tests/integration/test_login.pyc +0 -0
- data/vendor/tests/integration/test_promote.py +24 -0
- data/vendor/tests/integration/test_promote.pyc +0 -0
- data/vendor/tests/integration/test_token.py +33 -0
- data/vendor/tests/integration/test_token.pyc +0 -0
- data/vendor/tests/integration/test_whoami.py +24 -0
- data/vendor/tests/integration/test_whoami.pyc +0 -0
- data/vendor/tests/test_deploy.py +33 -0
- data/vendor/tests/test_deploy.pyc +0 -0
- data/vendor/tests/test_file_scanner.py +89 -0
- data/vendor/tests/test_file_scanner.pyc +0 -0
- data/vendor/tests/utils.py +78 -0
- data/vendor/tests/utils.pyc +0 -0
- data/vendor/wheel-0.30.0a0.dist-info/DESCRIPTION.rst +325 -0
- data/vendor/wheel-0.30.0a0.dist-info/INSTALLER +1 -0
- data/vendor/wheel-0.30.0a0.dist-info/LICENSE.txt +22 -0
- data/vendor/wheel-0.30.0a0.dist-info/METADATA +357 -0
- data/vendor/wheel-0.30.0a0.dist-info/RECORD +86 -0
- data/vendor/wheel-0.30.0a0.dist-info/WHEEL +6 -0
- data/vendor/wheel-0.30.0a0.dist-info/entry_points.txt +6 -0
- data/vendor/wheel-0.30.0a0.dist-info/metadata.json +1 -0
- data/vendor/wheel-0.30.0a0.dist-info/top_level.txt +1 -0
- data/vendor/yaml/__init__.py +315 -0
- data/vendor/yaml/__init__.pyc +0 -0
- data/vendor/yaml/composer.py +139 -0
- data/vendor/yaml/composer.pyc +0 -0
- data/vendor/yaml/constructor.py +675 -0
- data/vendor/yaml/constructor.pyc +0 -0
- data/vendor/yaml/cyaml.py +85 -0
- data/vendor/yaml/cyaml.pyc +0 -0
- data/vendor/yaml/dumper.py +62 -0
- data/vendor/yaml/dumper.pyc +0 -0
- data/vendor/yaml/emitter.py +1140 -0
- data/vendor/yaml/emitter.pyc +0 -0
- data/vendor/yaml/error.py +75 -0
- data/vendor/yaml/error.pyc +0 -0
- data/vendor/yaml/events.py +86 -0
- data/vendor/yaml/events.pyc +0 -0
- data/vendor/yaml/loader.py +40 -0
- data/vendor/yaml/loader.pyc +0 -0
- data/vendor/yaml/nodes.py +49 -0
- data/vendor/yaml/nodes.pyc +0 -0
- data/vendor/yaml/parser.py +589 -0
- data/vendor/yaml/parser.pyc +0 -0
- data/vendor/yaml/reader.py +190 -0
- data/vendor/yaml/reader.pyc +0 -0
- data/vendor/yaml/representer.py +486 -0
- data/vendor/yaml/representer.pyc +0 -0
- data/vendor/yaml/resolver.py +227 -0
- data/vendor/yaml/resolver.pyc +0 -0
- data/vendor/yaml/scanner.py +1453 -0
- data/vendor/yaml/scanner.pyc +0 -0
- data/vendor/yaml/serializer.py +111 -0
- data/vendor/yaml/serializer.pyc +0 -0
- data/vendor/yaml/tokens.py +104 -0
- data/vendor/yaml/tokens.pyc +0 -0
- metadata +407 -0
@@ -0,0 +1,1738 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
from contextlib import contextmanager
|
4
|
+
from itertools import repeat
|
5
|
+
from functools import update_wrapper
|
6
|
+
|
7
|
+
from .types import convert_type, IntRange, BOOL
|
8
|
+
from .utils import make_str, make_default_short_help, echo, get_os_args
|
9
|
+
from .exceptions import ClickException, UsageError, BadParameter, Abort, \
|
10
|
+
MissingParameter
|
11
|
+
from .termui import prompt, confirm
|
12
|
+
from .formatting import HelpFormatter, join_options
|
13
|
+
from .parser import OptionParser, split_opt
|
14
|
+
from .globals import push_context, pop_context
|
15
|
+
|
16
|
+
from ._compat import PY2, isidentifier, iteritems
|
17
|
+
from ._unicodefun import _check_for_unicode_literals, _verify_python3_env
|
18
|
+
|
19
|
+
|
20
|
+
_missing = object()
|
21
|
+
|
22
|
+
|
23
|
+
SUBCOMMAND_METAVAR = 'COMMAND [ARGS]...'
|
24
|
+
SUBCOMMANDS_METAVAR = 'COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...'
|
25
|
+
|
26
|
+
|
27
|
+
def _bashcomplete(cmd, prog_name, complete_var=None):
|
28
|
+
"""Internal handler for the bash completion support."""
|
29
|
+
if complete_var is None:
|
30
|
+
complete_var = '_%s_COMPLETE' % (prog_name.replace('-', '_')).upper()
|
31
|
+
complete_instr = os.environ.get(complete_var)
|
32
|
+
if not complete_instr:
|
33
|
+
return
|
34
|
+
|
35
|
+
from ._bashcomplete import bashcomplete
|
36
|
+
if bashcomplete(cmd, prog_name, complete_var, complete_instr):
|
37
|
+
sys.exit(1)
|
38
|
+
|
39
|
+
|
40
|
+
def _check_multicommand(base_command, cmd_name, cmd, register=False):
|
41
|
+
if not base_command.chain or not isinstance(cmd, MultiCommand):
|
42
|
+
return
|
43
|
+
if register:
|
44
|
+
hint = 'It is not possible to add multi commands as children to ' \
|
45
|
+
'another multi command that is in chain mode'
|
46
|
+
else:
|
47
|
+
hint = 'Found a multi command as subcommand to a multi command ' \
|
48
|
+
'that is in chain mode. This is not supported'
|
49
|
+
raise RuntimeError('%s. Command "%s" is set to chain and "%s" was '
|
50
|
+
'added as subcommand but it in itself is a '
|
51
|
+
'multi command. ("%s" is a %s within a chained '
|
52
|
+
'%s named "%s"). This restriction was supposed to '
|
53
|
+
'be lifted in 6.0 but the fix was flawed. This '
|
54
|
+
'will be fixed in Click 7.0' % (
|
55
|
+
hint, base_command.name, cmd_name,
|
56
|
+
cmd_name, cmd.__class__.__name__,
|
57
|
+
base_command.__class__.__name__,
|
58
|
+
base_command.name))
|
59
|
+
|
60
|
+
|
61
|
+
def batch(iterable, batch_size):
|
62
|
+
return list(zip(*repeat(iter(iterable), batch_size)))
|
63
|
+
|
64
|
+
|
65
|
+
def invoke_param_callback(callback, ctx, param, value):
|
66
|
+
code = getattr(callback, '__code__', None)
|
67
|
+
args = getattr(code, 'co_argcount', 3)
|
68
|
+
|
69
|
+
if args < 3:
|
70
|
+
# This will become a warning in Click 3.0:
|
71
|
+
from warnings import warn
|
72
|
+
warn(Warning('Invoked legacy parameter callback "%s". The new '
|
73
|
+
'signature for such callbacks starting with '
|
74
|
+
'click 2.0 is (ctx, param, value).'
|
75
|
+
% callback), stacklevel=3)
|
76
|
+
return callback(ctx, value)
|
77
|
+
return callback(ctx, param, value)
|
78
|
+
|
79
|
+
|
80
|
+
@contextmanager
|
81
|
+
def augment_usage_errors(ctx, param=None):
|
82
|
+
"""Context manager that attaches extra information to exceptions that
|
83
|
+
fly.
|
84
|
+
"""
|
85
|
+
try:
|
86
|
+
yield
|
87
|
+
except BadParameter as e:
|
88
|
+
if e.ctx is None:
|
89
|
+
e.ctx = ctx
|
90
|
+
if param is not None and e.param is None:
|
91
|
+
e.param = param
|
92
|
+
raise
|
93
|
+
except UsageError as e:
|
94
|
+
if e.ctx is None:
|
95
|
+
e.ctx = ctx
|
96
|
+
raise
|
97
|
+
|
98
|
+
|
99
|
+
def iter_params_for_processing(invocation_order, declaration_order):
|
100
|
+
"""Given a sequence of parameters in the order as should be considered
|
101
|
+
for processing and an iterable of parameters that exist, this returns
|
102
|
+
a list in the correct order as they should be processed.
|
103
|
+
"""
|
104
|
+
def sort_key(item):
|
105
|
+
try:
|
106
|
+
idx = invocation_order.index(item)
|
107
|
+
except ValueError:
|
108
|
+
idx = float('inf')
|
109
|
+
return (not item.is_eager, idx)
|
110
|
+
|
111
|
+
return sorted(declaration_order, key=sort_key)
|
112
|
+
|
113
|
+
|
114
|
+
class Context(object):
|
115
|
+
"""The context is a special internal object that holds state relevant
|
116
|
+
for the script execution at every single level. It's normally invisible
|
117
|
+
to commands unless they opt-in to getting access to it.
|
118
|
+
|
119
|
+
The context is useful as it can pass internal objects around and can
|
120
|
+
control special execution features such as reading data from
|
121
|
+
environment variables.
|
122
|
+
|
123
|
+
A context can be used as context manager in which case it will call
|
124
|
+
:meth:`close` on teardown.
|
125
|
+
|
126
|
+
.. versionadded:: 2.0
|
127
|
+
Added the `resilient_parsing`, `help_option_names`,
|
128
|
+
`token_normalize_func` parameters.
|
129
|
+
|
130
|
+
.. versionadded:: 3.0
|
131
|
+
Added the `allow_extra_args` and `allow_interspersed_args`
|
132
|
+
parameters.
|
133
|
+
|
134
|
+
.. versionadded:: 4.0
|
135
|
+
Added the `color`, `ignore_unknown_options`, and
|
136
|
+
`max_content_width` parameters.
|
137
|
+
|
138
|
+
:param command: the command class for this context.
|
139
|
+
:param parent: the parent context.
|
140
|
+
:param info_name: the info name for this invocation. Generally this
|
141
|
+
is the most descriptive name for the script or
|
142
|
+
command. For the toplevel script it is usually
|
143
|
+
the name of the script, for commands below it it's
|
144
|
+
the name of the script.
|
145
|
+
:param obj: an arbitrary object of user data.
|
146
|
+
:param auto_envvar_prefix: the prefix to use for automatic environment
|
147
|
+
variables. If this is `None` then reading
|
148
|
+
from environment variables is disabled. This
|
149
|
+
does not affect manually set environment
|
150
|
+
variables which are always read.
|
151
|
+
:param default_map: a dictionary (like object) with default values
|
152
|
+
for parameters.
|
153
|
+
:param terminal_width: the width of the terminal. The default is
|
154
|
+
inherit from parent context. If no context
|
155
|
+
defines the terminal width then auto
|
156
|
+
detection will be applied.
|
157
|
+
:param max_content_width: the maximum width for content rendered by
|
158
|
+
Click (this currently only affects help
|
159
|
+
pages). This defaults to 80 characters if
|
160
|
+
not overridden. In other words: even if the
|
161
|
+
terminal is larger than that, Click will not
|
162
|
+
format things wider than 80 characters by
|
163
|
+
default. In addition to that, formatters might
|
164
|
+
add some safety mapping on the right.
|
165
|
+
:param resilient_parsing: if this flag is enabled then Click will
|
166
|
+
parse without any interactivity or callback
|
167
|
+
invocation. This is useful for implementing
|
168
|
+
things such as completion support.
|
169
|
+
:param allow_extra_args: if this is set to `True` then extra arguments
|
170
|
+
at the end will not raise an error and will be
|
171
|
+
kept on the context. The default is to inherit
|
172
|
+
from the command.
|
173
|
+
:param allow_interspersed_args: if this is set to `False` then options
|
174
|
+
and arguments cannot be mixed. The
|
175
|
+
default is to inherit from the command.
|
176
|
+
:param ignore_unknown_options: instructs click to ignore options it does
|
177
|
+
not know and keeps them for later
|
178
|
+
processing.
|
179
|
+
:param help_option_names: optionally a list of strings that define how
|
180
|
+
the default help parameter is named. The
|
181
|
+
default is ``['--help']``.
|
182
|
+
:param token_normalize_func: an optional function that is used to
|
183
|
+
normalize tokens (options, choices,
|
184
|
+
etc.). This for instance can be used to
|
185
|
+
implement case insensitive behavior.
|
186
|
+
:param color: controls if the terminal supports ANSI colors or not. The
|
187
|
+
default is autodetection. This is only needed if ANSI
|
188
|
+
codes are used in texts that Click prints which is by
|
189
|
+
default not the case. This for instance would affect
|
190
|
+
help output.
|
191
|
+
"""
|
192
|
+
|
193
|
+
def __init__(self, command, parent=None, info_name=None, obj=None,
|
194
|
+
auto_envvar_prefix=None, default_map=None,
|
195
|
+
terminal_width=None, max_content_width=None,
|
196
|
+
resilient_parsing=False, allow_extra_args=None,
|
197
|
+
allow_interspersed_args=None,
|
198
|
+
ignore_unknown_options=None, help_option_names=None,
|
199
|
+
token_normalize_func=None, color=None):
|
200
|
+
#: the parent context or `None` if none exists.
|
201
|
+
self.parent = parent
|
202
|
+
#: the :class:`Command` for this context.
|
203
|
+
self.command = command
|
204
|
+
#: the descriptive information name
|
205
|
+
self.info_name = info_name
|
206
|
+
#: the parsed parameters except if the value is hidden in which
|
207
|
+
#: case it's not remembered.
|
208
|
+
self.params = {}
|
209
|
+
#: the leftover arguments.
|
210
|
+
self.args = []
|
211
|
+
#: protected arguments. These are arguments that are prepended
|
212
|
+
#: to `args` when certain parsing scenarios are encountered but
|
213
|
+
#: must be never propagated to another arguments. This is used
|
214
|
+
#: to implement nested parsing.
|
215
|
+
self.protected_args = []
|
216
|
+
if obj is None and parent is not None:
|
217
|
+
obj = parent.obj
|
218
|
+
#: the user object stored.
|
219
|
+
self.obj = obj
|
220
|
+
self._meta = getattr(parent, 'meta', {})
|
221
|
+
|
222
|
+
#: A dictionary (-like object) with defaults for parameters.
|
223
|
+
if default_map is None \
|
224
|
+
and parent is not None \
|
225
|
+
and parent.default_map is not None:
|
226
|
+
default_map = parent.default_map.get(info_name)
|
227
|
+
self.default_map = default_map
|
228
|
+
|
229
|
+
#: This flag indicates if a subcommand is going to be executed. A
|
230
|
+
#: group callback can use this information to figure out if it's
|
231
|
+
#: being executed directly or because the execution flow passes
|
232
|
+
#: onwards to a subcommand. By default it's None, but it can be
|
233
|
+
#: the name of the subcommand to execute.
|
234
|
+
#:
|
235
|
+
#: If chaining is enabled this will be set to ``'*'`` in case
|
236
|
+
#: any commands are executed. It is however not possible to
|
237
|
+
#: figure out which ones. If you require this knowledge you
|
238
|
+
#: should use a :func:`resultcallback`.
|
239
|
+
self.invoked_subcommand = None
|
240
|
+
|
241
|
+
if terminal_width is None and parent is not None:
|
242
|
+
terminal_width = parent.terminal_width
|
243
|
+
#: The width of the terminal (None is autodetection).
|
244
|
+
self.terminal_width = terminal_width
|
245
|
+
|
246
|
+
if max_content_width is None and parent is not None:
|
247
|
+
max_content_width = parent.max_content_width
|
248
|
+
#: The maximum width of formatted content (None implies a sensible
|
249
|
+
#: default which is 80 for most things).
|
250
|
+
self.max_content_width = max_content_width
|
251
|
+
|
252
|
+
if allow_extra_args is None:
|
253
|
+
allow_extra_args = command.allow_extra_args
|
254
|
+
#: Indicates if the context allows extra args or if it should
|
255
|
+
#: fail on parsing.
|
256
|
+
#:
|
257
|
+
#: .. versionadded:: 3.0
|
258
|
+
self.allow_extra_args = allow_extra_args
|
259
|
+
|
260
|
+
if allow_interspersed_args is None:
|
261
|
+
allow_interspersed_args = command.allow_interspersed_args
|
262
|
+
#: Indicates if the context allows mixing of arguments and
|
263
|
+
#: options or not.
|
264
|
+
#:
|
265
|
+
#: .. versionadded:: 3.0
|
266
|
+
self.allow_interspersed_args = allow_interspersed_args
|
267
|
+
|
268
|
+
if ignore_unknown_options is None:
|
269
|
+
ignore_unknown_options = command.ignore_unknown_options
|
270
|
+
#: Instructs click to ignore options that a command does not
|
271
|
+
#: understand and will store it on the context for later
|
272
|
+
#: processing. This is primarily useful for situations where you
|
273
|
+
#: want to call into external programs. Generally this pattern is
|
274
|
+
#: strongly discouraged because it's not possibly to losslessly
|
275
|
+
#: forward all arguments.
|
276
|
+
#:
|
277
|
+
#: .. versionadded:: 4.0
|
278
|
+
self.ignore_unknown_options = ignore_unknown_options
|
279
|
+
|
280
|
+
if help_option_names is None:
|
281
|
+
if parent is not None:
|
282
|
+
help_option_names = parent.help_option_names
|
283
|
+
else:
|
284
|
+
help_option_names = ['--help']
|
285
|
+
|
286
|
+
#: The names for the help options.
|
287
|
+
self.help_option_names = help_option_names
|
288
|
+
|
289
|
+
if token_normalize_func is None and parent is not None:
|
290
|
+
token_normalize_func = parent.token_normalize_func
|
291
|
+
|
292
|
+
#: An optional normalization function for tokens. This is
|
293
|
+
#: options, choices, commands etc.
|
294
|
+
self.token_normalize_func = token_normalize_func
|
295
|
+
|
296
|
+
#: Indicates if resilient parsing is enabled. In that case Click
|
297
|
+
#: will do its best to not cause any failures.
|
298
|
+
self.resilient_parsing = resilient_parsing
|
299
|
+
|
300
|
+
# If there is no envvar prefix yet, but the parent has one and
|
301
|
+
# the command on this level has a name, we can expand the envvar
|
302
|
+
# prefix automatically.
|
303
|
+
if auto_envvar_prefix is None:
|
304
|
+
if parent is not None \
|
305
|
+
and parent.auto_envvar_prefix is not None and \
|
306
|
+
self.info_name is not None:
|
307
|
+
auto_envvar_prefix = '%s_%s' % (parent.auto_envvar_prefix,
|
308
|
+
self.info_name.upper())
|
309
|
+
else:
|
310
|
+
self.auto_envvar_prefix = auto_envvar_prefix.upper()
|
311
|
+
self.auto_envvar_prefix = auto_envvar_prefix
|
312
|
+
|
313
|
+
if color is None and parent is not None:
|
314
|
+
color = parent.color
|
315
|
+
|
316
|
+
#: Controls if styling output is wanted or not.
|
317
|
+
self.color = color
|
318
|
+
|
319
|
+
self._close_callbacks = []
|
320
|
+
self._depth = 0
|
321
|
+
|
322
|
+
def __enter__(self):
|
323
|
+
self._depth += 1
|
324
|
+
push_context(self)
|
325
|
+
return self
|
326
|
+
|
327
|
+
def __exit__(self, exc_type, exc_value, tb):
|
328
|
+
self._depth -= 1
|
329
|
+
if self._depth == 0:
|
330
|
+
self.close()
|
331
|
+
pop_context()
|
332
|
+
|
333
|
+
@contextmanager
|
334
|
+
def scope(self, cleanup=True):
|
335
|
+
"""This helper method can be used with the context object to promote
|
336
|
+
it to the current thread local (see :func:`get_current_context`).
|
337
|
+
The default behavior of this is to invoke the cleanup functions which
|
338
|
+
can be disabled by setting `cleanup` to `False`. The cleanup
|
339
|
+
functions are typically used for things such as closing file handles.
|
340
|
+
|
341
|
+
If the cleanup is intended the context object can also be directly
|
342
|
+
used as a context manager.
|
343
|
+
|
344
|
+
Example usage::
|
345
|
+
|
346
|
+
with ctx.scope():
|
347
|
+
assert get_current_context() is ctx
|
348
|
+
|
349
|
+
This is equivalent::
|
350
|
+
|
351
|
+
with ctx:
|
352
|
+
assert get_current_context() is ctx
|
353
|
+
|
354
|
+
.. versionadded:: 5.0
|
355
|
+
|
356
|
+
:param cleanup: controls if the cleanup functions should be run or
|
357
|
+
not. The default is to run these functions. In
|
358
|
+
some situations the context only wants to be
|
359
|
+
temporarily pushed in which case this can be disabled.
|
360
|
+
Nested pushes automatically defer the cleanup.
|
361
|
+
"""
|
362
|
+
if not cleanup:
|
363
|
+
self._depth += 1
|
364
|
+
try:
|
365
|
+
with self as rv:
|
366
|
+
yield rv
|
367
|
+
finally:
|
368
|
+
if not cleanup:
|
369
|
+
self._depth -= 1
|
370
|
+
|
371
|
+
@property
|
372
|
+
def meta(self):
|
373
|
+
"""This is a dictionary which is shared with all the contexts
|
374
|
+
that are nested. It exists so that click utiltiies can store some
|
375
|
+
state here if they need to. It is however the responsibility of
|
376
|
+
that code to manage this dictionary well.
|
377
|
+
|
378
|
+
The keys are supposed to be unique dotted strings. For instance
|
379
|
+
module paths are a good choice for it. What is stored in there is
|
380
|
+
irrelevant for the operation of click. However what is important is
|
381
|
+
that code that places data here adheres to the general semantics of
|
382
|
+
the system.
|
383
|
+
|
384
|
+
Example usage::
|
385
|
+
|
386
|
+
LANG_KEY = __name__ + '.lang'
|
387
|
+
|
388
|
+
def set_language(value):
|
389
|
+
ctx = get_current_context()
|
390
|
+
ctx.meta[LANG_KEY] = value
|
391
|
+
|
392
|
+
def get_language():
|
393
|
+
return get_current_context().meta.get(LANG_KEY, 'en_US')
|
394
|
+
|
395
|
+
.. versionadded:: 5.0
|
396
|
+
"""
|
397
|
+
return self._meta
|
398
|
+
|
399
|
+
def make_formatter(self):
|
400
|
+
"""Creates the formatter for the help and usage output."""
|
401
|
+
return HelpFormatter(width=self.terminal_width,
|
402
|
+
max_width=self.max_content_width)
|
403
|
+
|
404
|
+
def call_on_close(self, f):
|
405
|
+
"""This decorator remembers a function as callback that should be
|
406
|
+
executed when the context tears down. This is most useful to bind
|
407
|
+
resource handling to the script execution. For instance, file objects
|
408
|
+
opened by the :class:`File` type will register their close callbacks
|
409
|
+
here.
|
410
|
+
|
411
|
+
:param f: the function to execute on teardown.
|
412
|
+
"""
|
413
|
+
self._close_callbacks.append(f)
|
414
|
+
return f
|
415
|
+
|
416
|
+
def close(self):
|
417
|
+
"""Invokes all close callbacks."""
|
418
|
+
for cb in self._close_callbacks:
|
419
|
+
cb()
|
420
|
+
self._close_callbacks = []
|
421
|
+
|
422
|
+
@property
|
423
|
+
def command_path(self):
|
424
|
+
"""The computed command path. This is used for the ``usage``
|
425
|
+
information on the help page. It's automatically created by
|
426
|
+
combining the info names of the chain of contexts to the root.
|
427
|
+
"""
|
428
|
+
rv = ''
|
429
|
+
if self.info_name is not None:
|
430
|
+
rv = self.info_name
|
431
|
+
if self.parent is not None:
|
432
|
+
rv = self.parent.command_path + ' ' + rv
|
433
|
+
return rv.lstrip()
|
434
|
+
|
435
|
+
def find_root(self):
|
436
|
+
"""Finds the outermost context."""
|
437
|
+
node = self
|
438
|
+
while node.parent is not None:
|
439
|
+
node = node.parent
|
440
|
+
return node
|
441
|
+
|
442
|
+
def find_object(self, object_type):
|
443
|
+
"""Finds the closest object of a given type."""
|
444
|
+
node = self
|
445
|
+
while node is not None:
|
446
|
+
if isinstance(node.obj, object_type):
|
447
|
+
return node.obj
|
448
|
+
node = node.parent
|
449
|
+
|
450
|
+
def ensure_object(self, object_type):
|
451
|
+
"""Like :meth:`find_object` but sets the innermost object to a
|
452
|
+
new instance of `object_type` if it does not exist.
|
453
|
+
"""
|
454
|
+
rv = self.find_object(object_type)
|
455
|
+
if rv is None:
|
456
|
+
self.obj = rv = object_type()
|
457
|
+
return rv
|
458
|
+
|
459
|
+
def lookup_default(self, name):
|
460
|
+
"""Looks up the default for a parameter name. This by default
|
461
|
+
looks into the :attr:`default_map` if available.
|
462
|
+
"""
|
463
|
+
if self.default_map is not None:
|
464
|
+
rv = self.default_map.get(name)
|
465
|
+
if callable(rv):
|
466
|
+
rv = rv()
|
467
|
+
return rv
|
468
|
+
|
469
|
+
def fail(self, message):
|
470
|
+
"""Aborts the execution of the program with a specific error
|
471
|
+
message.
|
472
|
+
|
473
|
+
:param message: the error message to fail with.
|
474
|
+
"""
|
475
|
+
raise UsageError(message, self)
|
476
|
+
|
477
|
+
def abort(self):
|
478
|
+
"""Aborts the script."""
|
479
|
+
raise Abort()
|
480
|
+
|
481
|
+
def exit(self, code=0):
|
482
|
+
"""Exits the application with a given exit code."""
|
483
|
+
sys.exit(code)
|
484
|
+
|
485
|
+
def get_usage(self):
|
486
|
+
"""Helper method to get formatted usage string for the current
|
487
|
+
context and command.
|
488
|
+
"""
|
489
|
+
return self.command.get_usage(self)
|
490
|
+
|
491
|
+
def get_help(self):
|
492
|
+
"""Helper method to get formatted help page for the current
|
493
|
+
context and command.
|
494
|
+
"""
|
495
|
+
return self.command.get_help(self)
|
496
|
+
|
497
|
+
def invoke(*args, **kwargs):
|
498
|
+
"""Invokes a command callback in exactly the way it expects. There
|
499
|
+
are two ways to invoke this method:
|
500
|
+
|
501
|
+
1. the first argument can be a callback and all other arguments and
|
502
|
+
keyword arguments are forwarded directly to the function.
|
503
|
+
2. the first argument is a click command object. In that case all
|
504
|
+
arguments are forwarded as well but proper click parameters
|
505
|
+
(options and click arguments) must be keyword arguments and Click
|
506
|
+
will fill in defaults.
|
507
|
+
|
508
|
+
Note that before Click 3.2 keyword arguments were not properly filled
|
509
|
+
in against the intention of this code and no context was created. For
|
510
|
+
more information about this change and why it was done in a bugfix
|
511
|
+
release see :ref:`upgrade-to-3.2`.
|
512
|
+
"""
|
513
|
+
self, callback = args[:2]
|
514
|
+
ctx = self
|
515
|
+
|
516
|
+
# It's also possible to invoke another command which might or
|
517
|
+
# might not have a callback. In that case we also fill
|
518
|
+
# in defaults and make a new context for this command.
|
519
|
+
if isinstance(callback, Command):
|
520
|
+
other_cmd = callback
|
521
|
+
callback = other_cmd.callback
|
522
|
+
ctx = Context(other_cmd, info_name=other_cmd.name, parent=self)
|
523
|
+
if callback is None:
|
524
|
+
raise TypeError('The given command does not have a '
|
525
|
+
'callback that can be invoked.')
|
526
|
+
|
527
|
+
for param in other_cmd.params:
|
528
|
+
if param.name not in kwargs and param.expose_value:
|
529
|
+
kwargs[param.name] = param.get_default(ctx)
|
530
|
+
|
531
|
+
args = args[2:]
|
532
|
+
with augment_usage_errors(self):
|
533
|
+
with ctx:
|
534
|
+
return callback(*args, **kwargs)
|
535
|
+
|
536
|
+
def forward(*args, **kwargs):
|
537
|
+
"""Similar to :meth:`invoke` but fills in default keyword
|
538
|
+
arguments from the current context if the other command expects
|
539
|
+
it. This cannot invoke callbacks directly, only other commands.
|
540
|
+
"""
|
541
|
+
self, cmd = args[:2]
|
542
|
+
|
543
|
+
# It's also possible to invoke another command which might or
|
544
|
+
# might not have a callback.
|
545
|
+
if not isinstance(cmd, Command):
|
546
|
+
raise TypeError('Callback is not a command.')
|
547
|
+
|
548
|
+
for param in self.params:
|
549
|
+
if param not in kwargs:
|
550
|
+
kwargs[param] = self.params[param]
|
551
|
+
|
552
|
+
return self.invoke(cmd, **kwargs)
|
553
|
+
|
554
|
+
|
555
|
+
class BaseCommand(object):
|
556
|
+
"""The base command implements the minimal API contract of commands.
|
557
|
+
Most code will never use this as it does not implement a lot of useful
|
558
|
+
functionality but it can act as the direct subclass of alternative
|
559
|
+
parsing methods that do not depend on the Click parser.
|
560
|
+
|
561
|
+
For instance, this can be used to bridge Click and other systems like
|
562
|
+
argparse or docopt.
|
563
|
+
|
564
|
+
Because base commands do not implement a lot of the API that other
|
565
|
+
parts of Click take for granted, they are not supported for all
|
566
|
+
operations. For instance, they cannot be used with the decorators
|
567
|
+
usually and they have no built-in callback system.
|
568
|
+
|
569
|
+
.. versionchanged:: 2.0
|
570
|
+
Added the `context_settings` parameter.
|
571
|
+
|
572
|
+
:param name: the name of the command to use unless a group overrides it.
|
573
|
+
:param context_settings: an optional dictionary with defaults that are
|
574
|
+
passed to the context object.
|
575
|
+
"""
|
576
|
+
#: the default for the :attr:`Context.allow_extra_args` flag.
|
577
|
+
allow_extra_args = False
|
578
|
+
#: the default for the :attr:`Context.allow_interspersed_args` flag.
|
579
|
+
allow_interspersed_args = True
|
580
|
+
#: the default for the :attr:`Context.ignore_unknown_options` flag.
|
581
|
+
ignore_unknown_options = False
|
582
|
+
|
583
|
+
def __init__(self, name, context_settings=None):
|
584
|
+
#: the name the command thinks it has. Upon registering a command
|
585
|
+
#: on a :class:`Group` the group will default the command name
|
586
|
+
#: with this information. You should instead use the
|
587
|
+
#: :class:`Context`\'s :attr:`~Context.info_name` attribute.
|
588
|
+
self.name = name
|
589
|
+
if context_settings is None:
|
590
|
+
context_settings = {}
|
591
|
+
#: an optional dictionary with defaults passed to the context.
|
592
|
+
self.context_settings = context_settings
|
593
|
+
|
594
|
+
def get_usage(self, ctx):
|
595
|
+
raise NotImplementedError('Base commands cannot get usage')
|
596
|
+
|
597
|
+
def get_help(self, ctx):
|
598
|
+
raise NotImplementedError('Base commands cannot get help')
|
599
|
+
|
600
|
+
def make_context(self, info_name, args, parent=None, **extra):
|
601
|
+
"""This function when given an info name and arguments will kick
|
602
|
+
off the parsing and create a new :class:`Context`. It does not
|
603
|
+
invoke the actual command callback though.
|
604
|
+
|
605
|
+
:param info_name: the info name for this invokation. Generally this
|
606
|
+
is the most descriptive name for the script or
|
607
|
+
command. For the toplevel script it's usually
|
608
|
+
the name of the script, for commands below it it's
|
609
|
+
the name of the script.
|
610
|
+
:param args: the arguments to parse as list of strings.
|
611
|
+
:param parent: the parent context if available.
|
612
|
+
:param extra: extra keyword arguments forwarded to the context
|
613
|
+
constructor.
|
614
|
+
"""
|
615
|
+
for key, value in iteritems(self.context_settings):
|
616
|
+
if key not in extra:
|
617
|
+
extra[key] = value
|
618
|
+
ctx = Context(self, info_name=info_name, parent=parent, **extra)
|
619
|
+
with ctx.scope(cleanup=False):
|
620
|
+
self.parse_args(ctx, args)
|
621
|
+
return ctx
|
622
|
+
|
623
|
+
def parse_args(self, ctx, args):
|
624
|
+
"""Given a context and a list of arguments this creates the parser
|
625
|
+
and parses the arguments, then modifies the context as necessary.
|
626
|
+
This is automatically invoked by :meth:`make_context`.
|
627
|
+
"""
|
628
|
+
raise NotImplementedError('Base commands do not know how to parse '
|
629
|
+
'arguments.')
|
630
|
+
|
631
|
+
def invoke(self, ctx):
|
632
|
+
"""Given a context, this invokes the command. The default
|
633
|
+
implementation is raising a not implemented error.
|
634
|
+
"""
|
635
|
+
raise NotImplementedError('Base commands are not invokable by default')
|
636
|
+
|
637
|
+
def main(self, args=None, prog_name=None, complete_var=None,
|
638
|
+
standalone_mode=True, **extra):
|
639
|
+
"""This is the way to invoke a script with all the bells and
|
640
|
+
whistles as a command line application. This will always terminate
|
641
|
+
the application after a call. If this is not wanted, ``SystemExit``
|
642
|
+
needs to be caught.
|
643
|
+
|
644
|
+
This method is also available by directly calling the instance of
|
645
|
+
a :class:`Command`.
|
646
|
+
|
647
|
+
.. versionadded:: 3.0
|
648
|
+
Added the `standalone_mode` flag to control the standalone mode.
|
649
|
+
|
650
|
+
:param args: the arguments that should be used for parsing. If not
|
651
|
+
provided, ``sys.argv[1:]`` is used.
|
652
|
+
:param prog_name: the program name that should be used. By default
|
653
|
+
the program name is constructed by taking the file
|
654
|
+
name from ``sys.argv[0]``.
|
655
|
+
:param complete_var: the environment variable that controls the
|
656
|
+
bash completion support. The default is
|
657
|
+
``"_<prog_name>_COMPLETE"`` with prog name in
|
658
|
+
uppercase.
|
659
|
+
:param standalone_mode: the default behavior is to invoke the script
|
660
|
+
in standalone mode. Click will then
|
661
|
+
handle exceptions and convert them into
|
662
|
+
error messages and the function will never
|
663
|
+
return but shut down the interpreter. If
|
664
|
+
this is set to `False` they will be
|
665
|
+
propagated to the caller and the return
|
666
|
+
value of this function is the return value
|
667
|
+
of :meth:`invoke`.
|
668
|
+
:param extra: extra keyword arguments are forwarded to the context
|
669
|
+
constructor. See :class:`Context` for more information.
|
670
|
+
"""
|
671
|
+
# If we are in Python 3, we will verify that the environment is
|
672
|
+
# sane at this point of reject further execution to avoid a
|
673
|
+
# broken script.
|
674
|
+
if not PY2:
|
675
|
+
_verify_python3_env()
|
676
|
+
else:
|
677
|
+
_check_for_unicode_literals()
|
678
|
+
|
679
|
+
if args is None:
|
680
|
+
args = get_os_args()
|
681
|
+
else:
|
682
|
+
args = list(args)
|
683
|
+
|
684
|
+
if prog_name is None:
|
685
|
+
prog_name = make_str(os.path.basename(
|
686
|
+
sys.argv and sys.argv[0] or __file__))
|
687
|
+
|
688
|
+
# Hook for the Bash completion. This only activates if the Bash
|
689
|
+
# completion is actually enabled, otherwise this is quite a fast
|
690
|
+
# noop.
|
691
|
+
_bashcomplete(self, prog_name, complete_var)
|
692
|
+
|
693
|
+
try:
|
694
|
+
try:
|
695
|
+
with self.make_context(prog_name, args, **extra) as ctx:
|
696
|
+
rv = self.invoke(ctx)
|
697
|
+
if not standalone_mode:
|
698
|
+
return rv
|
699
|
+
ctx.exit()
|
700
|
+
except (EOFError, KeyboardInterrupt):
|
701
|
+
echo(file=sys.stderr)
|
702
|
+
raise Abort()
|
703
|
+
except ClickException as e:
|
704
|
+
if not standalone_mode:
|
705
|
+
raise
|
706
|
+
e.show()
|
707
|
+
sys.exit(e.exit_code)
|
708
|
+
except Abort:
|
709
|
+
if not standalone_mode:
|
710
|
+
raise
|
711
|
+
echo('Aborted!', file=sys.stderr)
|
712
|
+
sys.exit(1)
|
713
|
+
|
714
|
+
def __call__(self, *args, **kwargs):
|
715
|
+
"""Alias for :meth:`main`."""
|
716
|
+
return self.main(*args, **kwargs)
|
717
|
+
|
718
|
+
|
719
|
+
class Command(BaseCommand):
|
720
|
+
"""Commands are the basic building block of command line interfaces in
|
721
|
+
Click. A basic command handles command line parsing and might dispatch
|
722
|
+
more parsing to commands nested below it.
|
723
|
+
|
724
|
+
.. versionchanged:: 2.0
|
725
|
+
Added the `context_settings` parameter.
|
726
|
+
|
727
|
+
:param name: the name of the command to use unless a group overrides it.
|
728
|
+
:param context_settings: an optional dictionary with defaults that are
|
729
|
+
passed to the context object.
|
730
|
+
:param callback: the callback to invoke. This is optional.
|
731
|
+
:param params: the parameters to register with this command. This can
|
732
|
+
be either :class:`Option` or :class:`Argument` objects.
|
733
|
+
:param help: the help string to use for this command.
|
734
|
+
:param epilog: like the help string but it's printed at the end of the
|
735
|
+
help page after everything else.
|
736
|
+
:param short_help: the short help to use for this command. This is
|
737
|
+
shown on the command listing of the parent command.
|
738
|
+
:param add_help_option: by default each command registers a ``--help``
|
739
|
+
option. This can be disabled by this parameter.
|
740
|
+
"""
|
741
|
+
|
742
|
+
def __init__(self, name, context_settings=None, callback=None,
|
743
|
+
params=None, help=None, epilog=None, short_help=None,
|
744
|
+
options_metavar='[OPTIONS]', add_help_option=True):
|
745
|
+
BaseCommand.__init__(self, name, context_settings)
|
746
|
+
#: the callback to execute when the command fires. This might be
|
747
|
+
#: `None` in which case nothing happens.
|
748
|
+
self.callback = callback
|
749
|
+
#: the list of parameters for this command in the order they
|
750
|
+
#: should show up in the help page and execute. Eager parameters
|
751
|
+
#: will automatically be handled before non eager ones.
|
752
|
+
self.params = params or []
|
753
|
+
self.help = help
|
754
|
+
self.epilog = epilog
|
755
|
+
self.options_metavar = options_metavar
|
756
|
+
if short_help is None and help:
|
757
|
+
short_help = make_default_short_help(help)
|
758
|
+
self.short_help = short_help
|
759
|
+
self.add_help_option = add_help_option
|
760
|
+
|
761
|
+
def get_usage(self, ctx):
|
762
|
+
formatter = ctx.make_formatter()
|
763
|
+
self.format_usage(ctx, formatter)
|
764
|
+
return formatter.getvalue().rstrip('\n')
|
765
|
+
|
766
|
+
def get_params(self, ctx):
|
767
|
+
rv = self.params
|
768
|
+
help_option = self.get_help_option(ctx)
|
769
|
+
if help_option is not None:
|
770
|
+
rv = rv + [help_option]
|
771
|
+
return rv
|
772
|
+
|
773
|
+
def format_usage(self, ctx, formatter):
|
774
|
+
"""Writes the usage line into the formatter."""
|
775
|
+
pieces = self.collect_usage_pieces(ctx)
|
776
|
+
formatter.write_usage(ctx.command_path, ' '.join(pieces))
|
777
|
+
|
778
|
+
def collect_usage_pieces(self, ctx):
|
779
|
+
"""Returns all the pieces that go into the usage line and returns
|
780
|
+
it as a list of strings.
|
781
|
+
"""
|
782
|
+
rv = [self.options_metavar]
|
783
|
+
for param in self.get_params(ctx):
|
784
|
+
rv.extend(param.get_usage_pieces(ctx))
|
785
|
+
return rv
|
786
|
+
|
787
|
+
def get_help_option_names(self, ctx):
|
788
|
+
"""Returns the names for the help option."""
|
789
|
+
all_names = set(ctx.help_option_names)
|
790
|
+
for param in self.params:
|
791
|
+
all_names.difference_update(param.opts)
|
792
|
+
all_names.difference_update(param.secondary_opts)
|
793
|
+
return all_names
|
794
|
+
|
795
|
+
def get_help_option(self, ctx):
|
796
|
+
"""Returns the help option object."""
|
797
|
+
help_options = self.get_help_option_names(ctx)
|
798
|
+
if not help_options or not self.add_help_option:
|
799
|
+
return
|
800
|
+
|
801
|
+
def show_help(ctx, param, value):
|
802
|
+
if value and not ctx.resilient_parsing:
|
803
|
+
echo(ctx.get_help(), color=ctx.color)
|
804
|
+
ctx.exit()
|
805
|
+
return Option(help_options, is_flag=True,
|
806
|
+
is_eager=True, expose_value=False,
|
807
|
+
callback=show_help,
|
808
|
+
help='Show this message and exit.')
|
809
|
+
|
810
|
+
def make_parser(self, ctx):
|
811
|
+
"""Creates the underlying option parser for this command."""
|
812
|
+
parser = OptionParser(ctx)
|
813
|
+
parser.allow_interspersed_args = ctx.allow_interspersed_args
|
814
|
+
parser.ignore_unknown_options = ctx.ignore_unknown_options
|
815
|
+
for param in self.get_params(ctx):
|
816
|
+
param.add_to_parser(parser, ctx)
|
817
|
+
return parser
|
818
|
+
|
819
|
+
def get_help(self, ctx):
|
820
|
+
"""Formats the help into a string and returns it. This creates a
|
821
|
+
formatter and will call into the following formatting methods:
|
822
|
+
"""
|
823
|
+
formatter = ctx.make_formatter()
|
824
|
+
self.format_help(ctx, formatter)
|
825
|
+
return formatter.getvalue().rstrip('\n')
|
826
|
+
|
827
|
+
def format_help(self, ctx, formatter):
|
828
|
+
"""Writes the help into the formatter if it exists.
|
829
|
+
|
830
|
+
This calls into the following methods:
|
831
|
+
|
832
|
+
- :meth:`format_usage`
|
833
|
+
- :meth:`format_help_text`
|
834
|
+
- :meth:`format_options`
|
835
|
+
- :meth:`format_epilog`
|
836
|
+
"""
|
837
|
+
self.format_usage(ctx, formatter)
|
838
|
+
self.format_help_text(ctx, formatter)
|
839
|
+
self.format_options(ctx, formatter)
|
840
|
+
self.format_epilog(ctx, formatter)
|
841
|
+
|
842
|
+
def format_help_text(self, ctx, formatter):
|
843
|
+
"""Writes the help text to the formatter if it exists."""
|
844
|
+
if self.help:
|
845
|
+
formatter.write_paragraph()
|
846
|
+
with formatter.indentation():
|
847
|
+
formatter.write_text(self.help)
|
848
|
+
|
849
|
+
def format_options(self, ctx, formatter):
|
850
|
+
"""Writes all the options into the formatter if they exist."""
|
851
|
+
opts = []
|
852
|
+
for param in self.get_params(ctx):
|
853
|
+
rv = param.get_help_record(ctx)
|
854
|
+
if rv is not None:
|
855
|
+
opts.append(rv)
|
856
|
+
|
857
|
+
if opts:
|
858
|
+
with formatter.section('Options'):
|
859
|
+
formatter.write_dl(opts)
|
860
|
+
|
861
|
+
def format_epilog(self, ctx, formatter):
|
862
|
+
"""Writes the epilog into the formatter if it exists."""
|
863
|
+
if self.epilog:
|
864
|
+
formatter.write_paragraph()
|
865
|
+
with formatter.indentation():
|
866
|
+
formatter.write_text(self.epilog)
|
867
|
+
|
868
|
+
def parse_args(self, ctx, args):
|
869
|
+
parser = self.make_parser(ctx)
|
870
|
+
opts, args, param_order = parser.parse_args(args=args)
|
871
|
+
|
872
|
+
for param in iter_params_for_processing(
|
873
|
+
param_order, self.get_params(ctx)):
|
874
|
+
value, args = param.handle_parse_result(ctx, opts, args)
|
875
|
+
|
876
|
+
if args and not ctx.allow_extra_args and not ctx.resilient_parsing:
|
877
|
+
ctx.fail('Got unexpected extra argument%s (%s)'
|
878
|
+
% (len(args) != 1 and 's' or '',
|
879
|
+
' '.join(map(make_str, args))))
|
880
|
+
|
881
|
+
ctx.args = args
|
882
|
+
return args
|
883
|
+
|
884
|
+
def invoke(self, ctx):
|
885
|
+
"""Given a context, this invokes the attached callback (if it exists)
|
886
|
+
in the right way.
|
887
|
+
"""
|
888
|
+
if self.callback is not None:
|
889
|
+
return ctx.invoke(self.callback, **ctx.params)
|
890
|
+
|
891
|
+
|
892
|
+
class MultiCommand(Command):
|
893
|
+
"""A multi command is the basic implementation of a command that
|
894
|
+
dispatches to subcommands. The most common version is the
|
895
|
+
:class:`Group`.
|
896
|
+
|
897
|
+
:param invoke_without_command: this controls how the multi command itself
|
898
|
+
is invoked. By default it's only invoked
|
899
|
+
if a subcommand is provided.
|
900
|
+
:param no_args_is_help: this controls what happens if no arguments are
|
901
|
+
provided. This option is enabled by default if
|
902
|
+
`invoke_without_command` is disabled or disabled
|
903
|
+
if it's enabled. If enabled this will add
|
904
|
+
``--help`` as argument if no arguments are
|
905
|
+
passed.
|
906
|
+
:param subcommand_metavar: the string that is used in the documentation
|
907
|
+
to indicate the subcommand place.
|
908
|
+
:param chain: if this is set to `True` chaining of multiple subcommands
|
909
|
+
is enabled. This restricts the form of commands in that
|
910
|
+
they cannot have optional arguments but it allows
|
911
|
+
multiple commands to be chained together.
|
912
|
+
:param result_callback: the result callback to attach to this multi
|
913
|
+
command.
|
914
|
+
"""
|
915
|
+
allow_extra_args = True
|
916
|
+
allow_interspersed_args = False
|
917
|
+
|
918
|
+
def __init__(self, name=None, invoke_without_command=False,
|
919
|
+
no_args_is_help=None, subcommand_metavar=None,
|
920
|
+
chain=False, result_callback=None, **attrs):
|
921
|
+
Command.__init__(self, name, **attrs)
|
922
|
+
if no_args_is_help is None:
|
923
|
+
no_args_is_help = not invoke_without_command
|
924
|
+
self.no_args_is_help = no_args_is_help
|
925
|
+
self.invoke_without_command = invoke_without_command
|
926
|
+
if subcommand_metavar is None:
|
927
|
+
if chain:
|
928
|
+
subcommand_metavar = SUBCOMMANDS_METAVAR
|
929
|
+
else:
|
930
|
+
subcommand_metavar = SUBCOMMAND_METAVAR
|
931
|
+
self.subcommand_metavar = subcommand_metavar
|
932
|
+
self.chain = chain
|
933
|
+
#: The result callback that is stored. This can be set or
|
934
|
+
#: overridden with the :func:`resultcallback` decorator.
|
935
|
+
self.result_callback = result_callback
|
936
|
+
|
937
|
+
if self.chain:
|
938
|
+
for param in self.params:
|
939
|
+
if isinstance(param, Argument) and not param.required:
|
940
|
+
raise RuntimeError('Multi commands in chain mode cannot '
|
941
|
+
'have optional arguments.')
|
942
|
+
|
943
|
+
def collect_usage_pieces(self, ctx):
|
944
|
+
rv = Command.collect_usage_pieces(self, ctx)
|
945
|
+
rv.append(self.subcommand_metavar)
|
946
|
+
return rv
|
947
|
+
|
948
|
+
def format_options(self, ctx, formatter):
|
949
|
+
Command.format_options(self, ctx, formatter)
|
950
|
+
self.format_commands(ctx, formatter)
|
951
|
+
|
952
|
+
def resultcallback(self, replace=False):
|
953
|
+
"""Adds a result callback to the chain command. By default if a
|
954
|
+
result callback is already registered this will chain them but
|
955
|
+
this can be disabled with the `replace` parameter. The result
|
956
|
+
callback is invoked with the return value of the subcommand
|
957
|
+
(or the list of return values from all subcommands if chaining
|
958
|
+
is enabled) as well as the parameters as they would be passed
|
959
|
+
to the main callback.
|
960
|
+
|
961
|
+
Example::
|
962
|
+
|
963
|
+
@click.group()
|
964
|
+
@click.option('-i', '--input', default=23)
|
965
|
+
def cli(input):
|
966
|
+
return 42
|
967
|
+
|
968
|
+
@cli.resultcallback()
|
969
|
+
def process_result(result, input):
|
970
|
+
return result + input
|
971
|
+
|
972
|
+
.. versionadded:: 3.0
|
973
|
+
|
974
|
+
:param replace: if set to `True` an already existing result
|
975
|
+
callback will be removed.
|
976
|
+
"""
|
977
|
+
def decorator(f):
|
978
|
+
old_callback = self.result_callback
|
979
|
+
if old_callback is None or replace:
|
980
|
+
self.result_callback = f
|
981
|
+
return f
|
982
|
+
def function(__value, *args, **kwargs):
|
983
|
+
return f(old_callback(__value, *args, **kwargs),
|
984
|
+
*args, **kwargs)
|
985
|
+
self.result_callback = rv = update_wrapper(function, f)
|
986
|
+
return rv
|
987
|
+
return decorator
|
988
|
+
|
989
|
+
def format_commands(self, ctx, formatter):
|
990
|
+
"""Extra format methods for multi methods that adds all the commands
|
991
|
+
after the options.
|
992
|
+
"""
|
993
|
+
rows = []
|
994
|
+
for subcommand in self.list_commands(ctx):
|
995
|
+
cmd = self.get_command(ctx, subcommand)
|
996
|
+
# What is this, the tool lied about a command. Ignore it
|
997
|
+
if cmd is None:
|
998
|
+
continue
|
999
|
+
|
1000
|
+
help = cmd.short_help or ''
|
1001
|
+
rows.append((subcommand, help))
|
1002
|
+
|
1003
|
+
if rows:
|
1004
|
+
with formatter.section('Commands'):
|
1005
|
+
formatter.write_dl(rows)
|
1006
|
+
|
1007
|
+
def parse_args(self, ctx, args):
|
1008
|
+
if not args and self.no_args_is_help and not ctx.resilient_parsing:
|
1009
|
+
echo(ctx.get_help(), color=ctx.color)
|
1010
|
+
ctx.exit()
|
1011
|
+
|
1012
|
+
rest = Command.parse_args(self, ctx, args)
|
1013
|
+
if self.chain:
|
1014
|
+
ctx.protected_args = rest
|
1015
|
+
ctx.args = []
|
1016
|
+
elif rest:
|
1017
|
+
ctx.protected_args, ctx.args = rest[:1], rest[1:]
|
1018
|
+
|
1019
|
+
return ctx.args
|
1020
|
+
|
1021
|
+
def invoke(self, ctx):
|
1022
|
+
def _process_result(value):
|
1023
|
+
if self.result_callback is not None:
|
1024
|
+
value = ctx.invoke(self.result_callback, value,
|
1025
|
+
**ctx.params)
|
1026
|
+
return value
|
1027
|
+
|
1028
|
+
if not ctx.protected_args:
|
1029
|
+
# If we are invoked without command the chain flag controls
|
1030
|
+
# how this happens. If we are not in chain mode, the return
|
1031
|
+
# value here is the return value of the command.
|
1032
|
+
# If however we are in chain mode, the return value is the
|
1033
|
+
# return value of the result processor invoked with an empty
|
1034
|
+
# list (which means that no subcommand actually was executed).
|
1035
|
+
if self.invoke_without_command:
|
1036
|
+
if not self.chain:
|
1037
|
+
return Command.invoke(self, ctx)
|
1038
|
+
with ctx:
|
1039
|
+
Command.invoke(self, ctx)
|
1040
|
+
return _process_result([])
|
1041
|
+
ctx.fail('Missing command.')
|
1042
|
+
|
1043
|
+
# Fetch args back out
|
1044
|
+
args = ctx.protected_args + ctx.args
|
1045
|
+
ctx.args = []
|
1046
|
+
ctx.protected_args = []
|
1047
|
+
|
1048
|
+
# If we're not in chain mode, we only allow the invocation of a
|
1049
|
+
# single command but we also inform the current context about the
|
1050
|
+
# name of the command to invoke.
|
1051
|
+
if not self.chain:
|
1052
|
+
# Make sure the context is entered so we do not clean up
|
1053
|
+
# resources until the result processor has worked.
|
1054
|
+
with ctx:
|
1055
|
+
cmd_name, cmd, args = self.resolve_command(ctx, args)
|
1056
|
+
ctx.invoked_subcommand = cmd_name
|
1057
|
+
Command.invoke(self, ctx)
|
1058
|
+
sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
|
1059
|
+
with sub_ctx:
|
1060
|
+
return _process_result(sub_ctx.command.invoke(sub_ctx))
|
1061
|
+
|
1062
|
+
# In chain mode we create the contexts step by step, but after the
|
1063
|
+
# base command has been invoked. Because at that point we do not
|
1064
|
+
# know the subcommands yet, the invoked subcommand attribute is
|
1065
|
+
# set to ``*`` to inform the command that subcommands are executed
|
1066
|
+
# but nothing else.
|
1067
|
+
with ctx:
|
1068
|
+
ctx.invoked_subcommand = args and '*' or None
|
1069
|
+
Command.invoke(self, ctx)
|
1070
|
+
|
1071
|
+
# Otherwise we make every single context and invoke them in a
|
1072
|
+
# chain. In that case the return value to the result processor
|
1073
|
+
# is the list of all invoked subcommand's results.
|
1074
|
+
contexts = []
|
1075
|
+
while args:
|
1076
|
+
cmd_name, cmd, args = self.resolve_command(ctx, args)
|
1077
|
+
sub_ctx = cmd.make_context(cmd_name, args, parent=ctx,
|
1078
|
+
allow_extra_args=True,
|
1079
|
+
allow_interspersed_args=False)
|
1080
|
+
contexts.append(sub_ctx)
|
1081
|
+
args, sub_ctx.args = sub_ctx.args, []
|
1082
|
+
|
1083
|
+
rv = []
|
1084
|
+
for sub_ctx in contexts:
|
1085
|
+
with sub_ctx:
|
1086
|
+
rv.append(sub_ctx.command.invoke(sub_ctx))
|
1087
|
+
return _process_result(rv)
|
1088
|
+
|
1089
|
+
def resolve_command(self, ctx, args):
|
1090
|
+
cmd_name = make_str(args[0])
|
1091
|
+
original_cmd_name = cmd_name
|
1092
|
+
|
1093
|
+
# Get the command
|
1094
|
+
cmd = self.get_command(ctx, cmd_name)
|
1095
|
+
|
1096
|
+
# If we can't find the command but there is a normalization
|
1097
|
+
# function available, we try with that one.
|
1098
|
+
if cmd is None and ctx.token_normalize_func is not None:
|
1099
|
+
cmd_name = ctx.token_normalize_func(cmd_name)
|
1100
|
+
cmd = self.get_command(ctx, cmd_name)
|
1101
|
+
|
1102
|
+
# If we don't find the command we want to show an error message
|
1103
|
+
# to the user that it was not provided. However, there is
|
1104
|
+
# something else we should do: if the first argument looks like
|
1105
|
+
# an option we want to kick off parsing again for arguments to
|
1106
|
+
# resolve things like --help which now should go to the main
|
1107
|
+
# place.
|
1108
|
+
if cmd is None:
|
1109
|
+
if split_opt(cmd_name)[0]:
|
1110
|
+
self.parse_args(ctx, ctx.args)
|
1111
|
+
ctx.fail('No such command "%s".' % original_cmd_name)
|
1112
|
+
|
1113
|
+
return cmd_name, cmd, args[1:]
|
1114
|
+
|
1115
|
+
def get_command(self, ctx, cmd_name):
|
1116
|
+
"""Given a context and a command name, this returns a
|
1117
|
+
:class:`Command` object if it exists or returns `None`.
|
1118
|
+
"""
|
1119
|
+
raise NotImplementedError()
|
1120
|
+
|
1121
|
+
def list_commands(self, ctx):
|
1122
|
+
"""Returns a list of subcommand names in the order they should
|
1123
|
+
appear.
|
1124
|
+
"""
|
1125
|
+
return []
|
1126
|
+
|
1127
|
+
|
1128
|
+
class Group(MultiCommand):
|
1129
|
+
"""A group allows a command to have subcommands attached. This is the
|
1130
|
+
most common way to implement nesting in Click.
|
1131
|
+
|
1132
|
+
:param commands: a dictionary of commands.
|
1133
|
+
"""
|
1134
|
+
|
1135
|
+
def __init__(self, name=None, commands=None, **attrs):
|
1136
|
+
MultiCommand.__init__(self, name, **attrs)
|
1137
|
+
#: the registered subcommands by their exported names.
|
1138
|
+
self.commands = commands or {}
|
1139
|
+
|
1140
|
+
def add_command(self, cmd, name=None):
|
1141
|
+
"""Registers another :class:`Command` with this group. If the name
|
1142
|
+
is not provided, the name of the command is used.
|
1143
|
+
"""
|
1144
|
+
name = name or cmd.name
|
1145
|
+
if name is None:
|
1146
|
+
raise TypeError('Command has no name.')
|
1147
|
+
_check_multicommand(self, name, cmd, register=True)
|
1148
|
+
self.commands[name] = cmd
|
1149
|
+
|
1150
|
+
def command(self, *args, **kwargs):
|
1151
|
+
"""A shortcut decorator for declaring and attaching a command to
|
1152
|
+
the group. This takes the same arguments as :func:`command` but
|
1153
|
+
immediately registers the created command with this instance by
|
1154
|
+
calling into :meth:`add_command`.
|
1155
|
+
"""
|
1156
|
+
def decorator(f):
|
1157
|
+
cmd = command(*args, **kwargs)(f)
|
1158
|
+
self.add_command(cmd)
|
1159
|
+
return cmd
|
1160
|
+
return decorator
|
1161
|
+
|
1162
|
+
def group(self, *args, **kwargs):
|
1163
|
+
"""A shortcut decorator for declaring and attaching a group to
|
1164
|
+
the group. This takes the same arguments as :func:`group` but
|
1165
|
+
immediately registers the created command with this instance by
|
1166
|
+
calling into :meth:`add_command`.
|
1167
|
+
"""
|
1168
|
+
def decorator(f):
|
1169
|
+
cmd = group(*args, **kwargs)(f)
|
1170
|
+
self.add_command(cmd)
|
1171
|
+
return cmd
|
1172
|
+
return decorator
|
1173
|
+
|
1174
|
+
def get_command(self, ctx, cmd_name):
|
1175
|
+
return self.commands.get(cmd_name)
|
1176
|
+
|
1177
|
+
def list_commands(self, ctx):
|
1178
|
+
return sorted(self.commands)
|
1179
|
+
|
1180
|
+
|
1181
|
+
class CommandCollection(MultiCommand):
|
1182
|
+
"""A command collection is a multi command that merges multiple multi
|
1183
|
+
commands together into one. This is a straightforward implementation
|
1184
|
+
that accepts a list of different multi commands as sources and
|
1185
|
+
provides all the commands for each of them.
|
1186
|
+
"""
|
1187
|
+
|
1188
|
+
def __init__(self, name=None, sources=None, **attrs):
|
1189
|
+
MultiCommand.__init__(self, name, **attrs)
|
1190
|
+
#: The list of registered multi commands.
|
1191
|
+
self.sources = sources or []
|
1192
|
+
|
1193
|
+
def add_source(self, multi_cmd):
|
1194
|
+
"""Adds a new multi command to the chain dispatcher."""
|
1195
|
+
self.sources.append(multi_cmd)
|
1196
|
+
|
1197
|
+
def get_command(self, ctx, cmd_name):
|
1198
|
+
for source in self.sources:
|
1199
|
+
rv = source.get_command(ctx, cmd_name)
|
1200
|
+
if rv is not None:
|
1201
|
+
if self.chain:
|
1202
|
+
_check_multicommand(self, cmd_name, rv)
|
1203
|
+
return rv
|
1204
|
+
|
1205
|
+
def list_commands(self, ctx):
|
1206
|
+
rv = set()
|
1207
|
+
for source in self.sources:
|
1208
|
+
rv.update(source.list_commands(ctx))
|
1209
|
+
return sorted(rv)
|
1210
|
+
|
1211
|
+
|
1212
|
+
class Parameter(object):
|
1213
|
+
"""A parameter to a command comes in two versions: they are either
|
1214
|
+
:class:`Option`\s or :class:`Argument`\s. Other subclasses are currently
|
1215
|
+
not supported by design as some of the internals for parsing are
|
1216
|
+
intentionally not finalized.
|
1217
|
+
|
1218
|
+
Some settings are supported by both options and arguments.
|
1219
|
+
|
1220
|
+
.. versionchanged:: 2.0
|
1221
|
+
Changed signature for parameter callback to also be passed the
|
1222
|
+
parameter. In Click 2.0, the old callback format will still work,
|
1223
|
+
but it will raise a warning to give you change to migrate the
|
1224
|
+
code easier.
|
1225
|
+
|
1226
|
+
:param param_decls: the parameter declarations for this option or
|
1227
|
+
argument. This is a list of flags or argument
|
1228
|
+
names.
|
1229
|
+
:param type: the type that should be used. Either a :class:`ParamType`
|
1230
|
+
or a Python type. The later is converted into the former
|
1231
|
+
automatically if supported.
|
1232
|
+
:param required: controls if this is optional or not.
|
1233
|
+
:param default: the default value if omitted. This can also be a callable,
|
1234
|
+
in which case it's invoked when the default is needed
|
1235
|
+
without any arguments.
|
1236
|
+
:param callback: a callback that should be executed after the parameter
|
1237
|
+
was matched. This is called as ``fn(ctx, param,
|
1238
|
+
value)`` and needs to return the value. Before Click
|
1239
|
+
2.0, the signature was ``(ctx, value)``.
|
1240
|
+
:param nargs: the number of arguments to match. If not ``1`` the return
|
1241
|
+
value is a tuple instead of single value. The default for
|
1242
|
+
nargs is ``1`` (except if the type is a tuple, then it's
|
1243
|
+
the arity of the tuple).
|
1244
|
+
:param metavar: how the value is represented in the help page.
|
1245
|
+
:param expose_value: if this is `True` then the value is passed onwards
|
1246
|
+
to the command callback and stored on the context,
|
1247
|
+
otherwise it's skipped.
|
1248
|
+
:param is_eager: eager values are processed before non eager ones. This
|
1249
|
+
should not be set for arguments or it will inverse the
|
1250
|
+
order of processing.
|
1251
|
+
:param envvar: a string or list of strings that are environment variables
|
1252
|
+
that should be checked.
|
1253
|
+
"""
|
1254
|
+
param_type_name = 'parameter'
|
1255
|
+
|
1256
|
+
def __init__(self, param_decls=None, type=None, required=False,
|
1257
|
+
default=None, callback=None, nargs=None, metavar=None,
|
1258
|
+
expose_value=True, is_eager=False, envvar=None):
|
1259
|
+
self.name, self.opts, self.secondary_opts = \
|
1260
|
+
self._parse_decls(param_decls or (), expose_value)
|
1261
|
+
|
1262
|
+
self.type = convert_type(type, default)
|
1263
|
+
|
1264
|
+
# Default nargs to what the type tells us if we have that
|
1265
|
+
# information available.
|
1266
|
+
if nargs is None:
|
1267
|
+
if self.type.is_composite:
|
1268
|
+
nargs = self.type.arity
|
1269
|
+
else:
|
1270
|
+
nargs = 1
|
1271
|
+
|
1272
|
+
self.required = required
|
1273
|
+
self.callback = callback
|
1274
|
+
self.nargs = nargs
|
1275
|
+
self.multiple = False
|
1276
|
+
self.expose_value = expose_value
|
1277
|
+
self.default = default
|
1278
|
+
self.is_eager = is_eager
|
1279
|
+
self.metavar = metavar
|
1280
|
+
self.envvar = envvar
|
1281
|
+
|
1282
|
+
@property
|
1283
|
+
def human_readable_name(self):
|
1284
|
+
"""Returns the human readable name of this parameter. This is the
|
1285
|
+
same as the name for options, but the metavar for arguments.
|
1286
|
+
"""
|
1287
|
+
return self.name
|
1288
|
+
|
1289
|
+
def make_metavar(self):
|
1290
|
+
if self.metavar is not None:
|
1291
|
+
return self.metavar
|
1292
|
+
metavar = self.type.get_metavar(self)
|
1293
|
+
if metavar is None:
|
1294
|
+
metavar = self.type.name.upper()
|
1295
|
+
if self.nargs != 1:
|
1296
|
+
metavar += '...'
|
1297
|
+
return metavar
|
1298
|
+
|
1299
|
+
def get_default(self, ctx):
|
1300
|
+
"""Given a context variable this calculates the default value."""
|
1301
|
+
# Otherwise go with the regular default.
|
1302
|
+
if callable(self.default):
|
1303
|
+
rv = self.default()
|
1304
|
+
else:
|
1305
|
+
rv = self.default
|
1306
|
+
return self.type_cast_value(ctx, rv)
|
1307
|
+
|
1308
|
+
def add_to_parser(self, parser, ctx):
|
1309
|
+
pass
|
1310
|
+
|
1311
|
+
def consume_value(self, ctx, opts):
|
1312
|
+
value = opts.get(self.name)
|
1313
|
+
if value is None:
|
1314
|
+
value = ctx.lookup_default(self.name)
|
1315
|
+
if value is None:
|
1316
|
+
value = self.value_from_envvar(ctx)
|
1317
|
+
return value
|
1318
|
+
|
1319
|
+
def type_cast_value(self, ctx, value):
|
1320
|
+
"""Given a value this runs it properly through the type system.
|
1321
|
+
This automatically handles things like `nargs` and `multiple` as
|
1322
|
+
well as composite types.
|
1323
|
+
"""
|
1324
|
+
if self.type.is_composite:
|
1325
|
+
if self.nargs <= 1:
|
1326
|
+
raise TypeError('Attempted to invoke composite type '
|
1327
|
+
'but nargs has been set to %s. This is '
|
1328
|
+
'not supported; nargs needs to be set to '
|
1329
|
+
'a fixed value > 1.' % self.nargs)
|
1330
|
+
if self.multiple:
|
1331
|
+
return tuple(self.type(x or (), self, ctx) for x in value or ())
|
1332
|
+
return self.type(value or (), self, ctx)
|
1333
|
+
|
1334
|
+
def _convert(value, level):
|
1335
|
+
if level == 0:
|
1336
|
+
return self.type(value, self, ctx)
|
1337
|
+
return tuple(_convert(x, level - 1) for x in value or ())
|
1338
|
+
return _convert(value, (self.nargs != 1) + bool(self.multiple))
|
1339
|
+
|
1340
|
+
def process_value(self, ctx, value):
|
1341
|
+
"""Given a value and context this runs the logic to convert the
|
1342
|
+
value as necessary.
|
1343
|
+
"""
|
1344
|
+
# If the value we were given is None we do nothing. This way
|
1345
|
+
# code that calls this can easily figure out if something was
|
1346
|
+
# not provided. Otherwise it would be converted into an empty
|
1347
|
+
# tuple for multiple invocations which is inconvenient.
|
1348
|
+
if value is not None:
|
1349
|
+
return self.type_cast_value(ctx, value)
|
1350
|
+
|
1351
|
+
def value_is_missing(self, value):
|
1352
|
+
if value is None:
|
1353
|
+
return True
|
1354
|
+
if (self.nargs != 1 or self.multiple) and value == ():
|
1355
|
+
return True
|
1356
|
+
return False
|
1357
|
+
|
1358
|
+
def full_process_value(self, ctx, value):
|
1359
|
+
value = self.process_value(ctx, value)
|
1360
|
+
|
1361
|
+
if value is None:
|
1362
|
+
value = self.get_default(ctx)
|
1363
|
+
|
1364
|
+
if self.required and self.value_is_missing(value):
|
1365
|
+
raise MissingParameter(ctx=ctx, param=self)
|
1366
|
+
|
1367
|
+
return value
|
1368
|
+
|
1369
|
+
def resolve_envvar_value(self, ctx):
|
1370
|
+
if self.envvar is None:
|
1371
|
+
return
|
1372
|
+
if isinstance(self.envvar, (tuple, list)):
|
1373
|
+
for envvar in self.envvar:
|
1374
|
+
rv = os.environ.get(envvar)
|
1375
|
+
if rv is not None:
|
1376
|
+
return rv
|
1377
|
+
else:
|
1378
|
+
return os.environ.get(self.envvar)
|
1379
|
+
|
1380
|
+
def value_from_envvar(self, ctx):
|
1381
|
+
rv = self.resolve_envvar_value(ctx)
|
1382
|
+
if rv is not None and self.nargs != 1:
|
1383
|
+
rv = self.type.split_envvar_value(rv)
|
1384
|
+
return rv
|
1385
|
+
|
1386
|
+
def handle_parse_result(self, ctx, opts, args):
|
1387
|
+
with augment_usage_errors(ctx, param=self):
|
1388
|
+
value = self.consume_value(ctx, opts)
|
1389
|
+
try:
|
1390
|
+
value = self.full_process_value(ctx, value)
|
1391
|
+
except Exception:
|
1392
|
+
if not ctx.resilient_parsing:
|
1393
|
+
raise
|
1394
|
+
value = None
|
1395
|
+
if self.callback is not None:
|
1396
|
+
try:
|
1397
|
+
value = invoke_param_callback(
|
1398
|
+
self.callback, ctx, self, value)
|
1399
|
+
except Exception:
|
1400
|
+
if not ctx.resilient_parsing:
|
1401
|
+
raise
|
1402
|
+
|
1403
|
+
if self.expose_value:
|
1404
|
+
ctx.params[self.name] = value
|
1405
|
+
return value, args
|
1406
|
+
|
1407
|
+
def get_help_record(self, ctx):
|
1408
|
+
pass
|
1409
|
+
|
1410
|
+
def get_usage_pieces(self, ctx):
|
1411
|
+
return []
|
1412
|
+
|
1413
|
+
|
1414
|
+
class Option(Parameter):
|
1415
|
+
"""Options are usually optional values on the command line and
|
1416
|
+
have some extra features that arguments don't have.
|
1417
|
+
|
1418
|
+
All other parameters are passed onwards to the parameter constructor.
|
1419
|
+
|
1420
|
+
:param show_default: controls if the default value should be shown on the
|
1421
|
+
help page. Normally, defaults are not shown.
|
1422
|
+
:param prompt: if set to `True` or a non empty string then the user will
|
1423
|
+
be prompted for input if not set. If set to `True` the
|
1424
|
+
prompt will be the option name capitalized.
|
1425
|
+
:param confirmation_prompt: if set then the value will need to be confirmed
|
1426
|
+
if it was prompted for.
|
1427
|
+
:param hide_input: if this is `True` then the input on the prompt will be
|
1428
|
+
hidden from the user. This is useful for password
|
1429
|
+
input.
|
1430
|
+
:param is_flag: forces this option to act as a flag. The default is
|
1431
|
+
auto detection.
|
1432
|
+
:param flag_value: which value should be used for this flag if it's
|
1433
|
+
enabled. This is set to a boolean automatically if
|
1434
|
+
the option string contains a slash to mark two options.
|
1435
|
+
:param multiple: if this is set to `True` then the argument is accepted
|
1436
|
+
multiple times and recorded. This is similar to ``nargs``
|
1437
|
+
in how it works but supports arbitrary number of
|
1438
|
+
arguments.
|
1439
|
+
:param count: this flag makes an option increment an integer.
|
1440
|
+
:param allow_from_autoenv: if this is enabled then the value of this
|
1441
|
+
parameter will be pulled from an environment
|
1442
|
+
variable in case a prefix is defined on the
|
1443
|
+
context.
|
1444
|
+
:param help: the help string.
|
1445
|
+
"""
|
1446
|
+
param_type_name = 'option'
|
1447
|
+
|
1448
|
+
def __init__(self, param_decls=None, show_default=False,
|
1449
|
+
prompt=False, confirmation_prompt=False,
|
1450
|
+
hide_input=False, is_flag=None, flag_value=None,
|
1451
|
+
multiple=False, count=False, allow_from_autoenv=True,
|
1452
|
+
type=None, help=None, **attrs):
|
1453
|
+
default_is_missing = attrs.get('default', _missing) is _missing
|
1454
|
+
Parameter.__init__(self, param_decls, type=type, **attrs)
|
1455
|
+
|
1456
|
+
if prompt is True:
|
1457
|
+
prompt_text = self.name.replace('_', ' ').capitalize()
|
1458
|
+
elif prompt is False:
|
1459
|
+
prompt_text = None
|
1460
|
+
else:
|
1461
|
+
prompt_text = prompt
|
1462
|
+
self.prompt = prompt_text
|
1463
|
+
self.confirmation_prompt = confirmation_prompt
|
1464
|
+
self.hide_input = hide_input
|
1465
|
+
|
1466
|
+
# Flags
|
1467
|
+
if is_flag is None:
|
1468
|
+
if flag_value is not None:
|
1469
|
+
is_flag = True
|
1470
|
+
else:
|
1471
|
+
is_flag = bool(self.secondary_opts)
|
1472
|
+
if is_flag and default_is_missing:
|
1473
|
+
self.default = False
|
1474
|
+
if flag_value is None:
|
1475
|
+
flag_value = not self.default
|
1476
|
+
self.is_flag = is_flag
|
1477
|
+
self.flag_value = flag_value
|
1478
|
+
if self.is_flag and isinstance(self.flag_value, bool) \
|
1479
|
+
and type is None:
|
1480
|
+
self.type = BOOL
|
1481
|
+
self.is_bool_flag = True
|
1482
|
+
else:
|
1483
|
+
self.is_bool_flag = False
|
1484
|
+
|
1485
|
+
# Counting
|
1486
|
+
self.count = count
|
1487
|
+
if count:
|
1488
|
+
if type is None:
|
1489
|
+
self.type = IntRange(min=0)
|
1490
|
+
if default_is_missing:
|
1491
|
+
self.default = 0
|
1492
|
+
|
1493
|
+
self.multiple = multiple
|
1494
|
+
self.allow_from_autoenv = allow_from_autoenv
|
1495
|
+
self.help = help
|
1496
|
+
self.show_default = show_default
|
1497
|
+
|
1498
|
+
# Sanity check for stuff we don't support
|
1499
|
+
if __debug__:
|
1500
|
+
if self.nargs < 0:
|
1501
|
+
raise TypeError('Options cannot have nargs < 0')
|
1502
|
+
if self.prompt and self.is_flag and not self.is_bool_flag:
|
1503
|
+
raise TypeError('Cannot prompt for flags that are not bools.')
|
1504
|
+
if not self.is_bool_flag and self.secondary_opts:
|
1505
|
+
raise TypeError('Got secondary option for non boolean flag.')
|
1506
|
+
if self.is_bool_flag and self.hide_input \
|
1507
|
+
and self.prompt is not None:
|
1508
|
+
raise TypeError('Hidden input does not work with boolean '
|
1509
|
+
'flag prompts.')
|
1510
|
+
if self.count:
|
1511
|
+
if self.multiple:
|
1512
|
+
raise TypeError('Options cannot be multiple and count '
|
1513
|
+
'at the same time.')
|
1514
|
+
elif self.is_flag:
|
1515
|
+
raise TypeError('Options cannot be count and flags at '
|
1516
|
+
'the same time.')
|
1517
|
+
|
1518
|
+
def _parse_decls(self, decls, expose_value):
|
1519
|
+
opts = []
|
1520
|
+
secondary_opts = []
|
1521
|
+
name = None
|
1522
|
+
possible_names = []
|
1523
|
+
|
1524
|
+
for decl in decls:
|
1525
|
+
if isidentifier(decl):
|
1526
|
+
if name is not None:
|
1527
|
+
raise TypeError('Name defined twice')
|
1528
|
+
name = decl
|
1529
|
+
else:
|
1530
|
+
split_char = decl[:1] == '/' and ';' or '/'
|
1531
|
+
if split_char in decl:
|
1532
|
+
first, second = decl.split(split_char, 1)
|
1533
|
+
first = first.rstrip()
|
1534
|
+
if first:
|
1535
|
+
possible_names.append(split_opt(first))
|
1536
|
+
opts.append(first)
|
1537
|
+
second = second.lstrip()
|
1538
|
+
if second:
|
1539
|
+
secondary_opts.append(second.lstrip())
|
1540
|
+
else:
|
1541
|
+
possible_names.append(split_opt(decl))
|
1542
|
+
opts.append(decl)
|
1543
|
+
|
1544
|
+
if name is None and possible_names:
|
1545
|
+
possible_names.sort(key=lambda x: len(x[0]))
|
1546
|
+
name = possible_names[-1][1].replace('-', '_').lower()
|
1547
|
+
if not isidentifier(name):
|
1548
|
+
name = None
|
1549
|
+
|
1550
|
+
if name is None:
|
1551
|
+
if not expose_value:
|
1552
|
+
return None, opts, secondary_opts
|
1553
|
+
raise TypeError('Could not determine name for option')
|
1554
|
+
|
1555
|
+
if not opts and not secondary_opts:
|
1556
|
+
raise TypeError('No options defined but a name was passed (%s). '
|
1557
|
+
'Did you mean to declare an argument instead '
|
1558
|
+
'of an option?' % name)
|
1559
|
+
|
1560
|
+
return name, opts, secondary_opts
|
1561
|
+
|
1562
|
+
def add_to_parser(self, parser, ctx):
|
1563
|
+
kwargs = {
|
1564
|
+
'dest': self.name,
|
1565
|
+
'nargs': self.nargs,
|
1566
|
+
'obj': self,
|
1567
|
+
}
|
1568
|
+
|
1569
|
+
if self.multiple:
|
1570
|
+
action = 'append'
|
1571
|
+
elif self.count:
|
1572
|
+
action = 'count'
|
1573
|
+
else:
|
1574
|
+
action = 'store'
|
1575
|
+
|
1576
|
+
if self.is_flag:
|
1577
|
+
kwargs.pop('nargs', None)
|
1578
|
+
if self.is_bool_flag and self.secondary_opts:
|
1579
|
+
parser.add_option(self.opts, action=action + '_const',
|
1580
|
+
const=True, **kwargs)
|
1581
|
+
parser.add_option(self.secondary_opts, action=action +
|
1582
|
+
'_const', const=False, **kwargs)
|
1583
|
+
else:
|
1584
|
+
parser.add_option(self.opts, action=action + '_const',
|
1585
|
+
const=self.flag_value,
|
1586
|
+
**kwargs)
|
1587
|
+
else:
|
1588
|
+
kwargs['action'] = action
|
1589
|
+
parser.add_option(self.opts, **kwargs)
|
1590
|
+
|
1591
|
+
def get_help_record(self, ctx):
|
1592
|
+
any_prefix_is_slash = []
|
1593
|
+
|
1594
|
+
def _write_opts(opts):
|
1595
|
+
rv, any_slashes = join_options(opts)
|
1596
|
+
if any_slashes:
|
1597
|
+
any_prefix_is_slash[:] = [True]
|
1598
|
+
if not self.is_flag and not self.count:
|
1599
|
+
rv += ' ' + self.make_metavar()
|
1600
|
+
return rv
|
1601
|
+
|
1602
|
+
rv = [_write_opts(self.opts)]
|
1603
|
+
if self.secondary_opts:
|
1604
|
+
rv.append(_write_opts(self.secondary_opts))
|
1605
|
+
|
1606
|
+
help = self.help or ''
|
1607
|
+
extra = []
|
1608
|
+
if self.default is not None and self.show_default:
|
1609
|
+
extra.append('default: %s' % (
|
1610
|
+
', '.join('%s' % d for d in self.default)
|
1611
|
+
if isinstance(self.default, (list, tuple))
|
1612
|
+
else self.default, ))
|
1613
|
+
if self.required:
|
1614
|
+
extra.append('required')
|
1615
|
+
if extra:
|
1616
|
+
help = '%s[%s]' % (help and help + ' ' or '', '; '.join(extra))
|
1617
|
+
|
1618
|
+
return ((any_prefix_is_slash and '; ' or ' / ').join(rv), help)
|
1619
|
+
|
1620
|
+
def get_default(self, ctx):
|
1621
|
+
# If we're a non boolean flag out default is more complex because
|
1622
|
+
# we need to look at all flags in the same group to figure out
|
1623
|
+
# if we're the the default one in which case we return the flag
|
1624
|
+
# value as default.
|
1625
|
+
if self.is_flag and not self.is_bool_flag:
|
1626
|
+
for param in ctx.command.params:
|
1627
|
+
if param.name == self.name and param.default:
|
1628
|
+
return param.flag_value
|
1629
|
+
return None
|
1630
|
+
return Parameter.get_default(self, ctx)
|
1631
|
+
|
1632
|
+
def prompt_for_value(self, ctx):
|
1633
|
+
"""This is an alternative flow that can be activated in the full
|
1634
|
+
value processing if a value does not exist. It will prompt the
|
1635
|
+
user until a valid value exists and then returns the processed
|
1636
|
+
value as result.
|
1637
|
+
"""
|
1638
|
+
# Calculate the default before prompting anything to be stable.
|
1639
|
+
default = self.get_default(ctx)
|
1640
|
+
|
1641
|
+
# If this is a prompt for a flag we need to handle this
|
1642
|
+
# differently.
|
1643
|
+
if self.is_bool_flag:
|
1644
|
+
return confirm(self.prompt, default)
|
1645
|
+
|
1646
|
+
return prompt(self.prompt, default=default,
|
1647
|
+
hide_input=self.hide_input,
|
1648
|
+
confirmation_prompt=self.confirmation_prompt,
|
1649
|
+
value_proc=lambda x: self.process_value(ctx, x))
|
1650
|
+
|
1651
|
+
def resolve_envvar_value(self, ctx):
|
1652
|
+
rv = Parameter.resolve_envvar_value(self, ctx)
|
1653
|
+
if rv is not None:
|
1654
|
+
return rv
|
1655
|
+
if self.allow_from_autoenv and \
|
1656
|
+
ctx.auto_envvar_prefix is not None:
|
1657
|
+
envvar = '%s_%s' % (ctx.auto_envvar_prefix, self.name.upper())
|
1658
|
+
return os.environ.get(envvar)
|
1659
|
+
|
1660
|
+
def value_from_envvar(self, ctx):
|
1661
|
+
rv = self.resolve_envvar_value(ctx)
|
1662
|
+
if rv is None:
|
1663
|
+
return None
|
1664
|
+
value_depth = (self.nargs != 1) + bool(self.multiple)
|
1665
|
+
if value_depth > 0 and rv is not None:
|
1666
|
+
rv = self.type.split_envvar_value(rv)
|
1667
|
+
if self.multiple and self.nargs != 1:
|
1668
|
+
rv = batch(rv, self.nargs)
|
1669
|
+
return rv
|
1670
|
+
|
1671
|
+
def full_process_value(self, ctx, value):
|
1672
|
+
if value is None and self.prompt is not None \
|
1673
|
+
and not ctx.resilient_parsing:
|
1674
|
+
return self.prompt_for_value(ctx)
|
1675
|
+
return Parameter.full_process_value(self, ctx, value)
|
1676
|
+
|
1677
|
+
|
1678
|
+
class Argument(Parameter):
|
1679
|
+
"""Arguments are positional parameters to a command. They generally
|
1680
|
+
provide fewer features than options but can have infinite ``nargs``
|
1681
|
+
and are required by default.
|
1682
|
+
|
1683
|
+
All parameters are passed onwards to the parameter constructor.
|
1684
|
+
"""
|
1685
|
+
param_type_name = 'argument'
|
1686
|
+
|
1687
|
+
def __init__(self, param_decls, required=None, **attrs):
|
1688
|
+
if required is None:
|
1689
|
+
if attrs.get('default') is not None:
|
1690
|
+
required = False
|
1691
|
+
else:
|
1692
|
+
required = attrs.get('nargs', 1) > 0
|
1693
|
+
Parameter.__init__(self, param_decls, required=required, **attrs)
|
1694
|
+
if self.default is not None and self.nargs < 0:
|
1695
|
+
raise TypeError('nargs=-1 in combination with a default value '
|
1696
|
+
'is not supported.')
|
1697
|
+
|
1698
|
+
@property
|
1699
|
+
def human_readable_name(self):
|
1700
|
+
if self.metavar is not None:
|
1701
|
+
return self.metavar
|
1702
|
+
return self.name.upper()
|
1703
|
+
|
1704
|
+
def make_metavar(self):
|
1705
|
+
if self.metavar is not None:
|
1706
|
+
return self.metavar
|
1707
|
+
var = self.name.upper()
|
1708
|
+
if not self.required:
|
1709
|
+
var = '[%s]' % var
|
1710
|
+
if self.nargs != 1:
|
1711
|
+
var += '...'
|
1712
|
+
return var
|
1713
|
+
|
1714
|
+
def _parse_decls(self, decls, expose_value):
|
1715
|
+
if not decls:
|
1716
|
+
if not expose_value:
|
1717
|
+
return None, [], []
|
1718
|
+
raise TypeError('Could not determine name for argument')
|
1719
|
+
if len(decls) == 1:
|
1720
|
+
name = arg = decls[0]
|
1721
|
+
name = name.replace('-', '_').lower()
|
1722
|
+
elif len(decls) == 2:
|
1723
|
+
name, arg = decls
|
1724
|
+
else:
|
1725
|
+
raise TypeError('Arguments take exactly one or two '
|
1726
|
+
'parameter declarations, got %d' % len(decls))
|
1727
|
+
return name, [arg], []
|
1728
|
+
|
1729
|
+
def get_usage_pieces(self, ctx):
|
1730
|
+
return [self.make_metavar()]
|
1731
|
+
|
1732
|
+
def add_to_parser(self, parser, ctx):
|
1733
|
+
parser.add_argument(dest=self.name, nargs=self.nargs,
|
1734
|
+
obj=self)
|
1735
|
+
|
1736
|
+
|
1737
|
+
# Circular dependency between decorators and core
|
1738
|
+
from .decorators import command, group
|