import typing as t from gettext import gettext as _ from gettext import ngettext
from ._compat import get_text_stderr from .utils import echo from .utils import format_filename
if t.TYPE_CHECKING: from .core import Command from .core import Context from .core import Parameter
def _join_param_hints(
param_hint: t.Optional[t.Union[t.Sequence[str], str]]
) -> t.Optional[str]: if param_hint isnotNoneandnot isinstance(param_hint, str): return" / ".join(repr(x) for x in param_hint)
return param_hint
class ClickException(Exception): """An exception that Click can handle and show to the user."""
#: The exit code for this exception.
exit_code = 1
class UsageError(ClickException): """An internal exception that signals a usage error. This typically
aborts any further handling.
:param message: the error message to display.
:param ctx: optionally the context that caused this error. Click will
fill in the context automatically in some situations. """
def show(self, file: t.Optional[t.IO[t.Any]] = None) -> None: if file isNone:
file = get_text_stderr()
color = None
hint = "" if (
self.ctx isnotNone and self.ctx.command.get_help_option(self.ctx) isnotNone
):
hint = _("Try '{command} {option}' for help.").format(
command=self.ctx.command_path, option=self.ctx.help_option_names[0]
)
hint = f"{hint}\n" if self.ctx isnotNone:
color = self.ctx.color
echo(f"{self.ctx.get_usage()}\n{hint}", file=file, color=color)
echo(
_("Error: {message}").format(message=self.format_message()),
file=file,
color=color,
)
class BadParameter(UsageError): """An exception that formats out a standardized error message for a
bad parameter. This is useful when thrown from a callback or type as
Click will attach contextual information to it (for instance, which
parameter it is).
.. versionadded:: 2.0
:param param: the parameter object that caused this error. This can
be left out, and Click will attach this info itself if possible.
:param param_hint: a string that shows up as parameter name. This
can be used as alternative to `param` in cases
where custom validation should happen. If it is
a string it's used as such, if it's a list then
each item is quoted and separated. """
return _("Invalid value for {param_hint}: {message}").format(
param_hint=_join_param_hints(param_hint), message=self.message
)
class MissingParameter(BadParameter): """Raised if click required an option or argument but it was not
provided when invoking the script.
.. versionadded:: 4.0
:param param_type: a string that indicates the type of the parameter.
The default is to inherit the parameter type from
the given `param`. Valid values are ``'parameter'``,
``'option'`` or ``'argument'``. """
possibility_str = ", ".join(sorted(self.possibilities))
suggest = ngettext( "Did you mean {possibility}?", "(Possible options: {possibilities})",
len(self.possibilities),
).format(possibility=possibility_str, possibilities=possibility_str) return f"{self.message} {suggest}"
class BadOptionUsage(UsageError): """Raised if an option is generally supplied but the use of the option
was incorrect. This isfor instance raised if the number of arguments for an option isnot correct.
.. versionadded:: 4.0
:param option_name: the name of the option being used incorrectly. """
class BadArgumentUsage(UsageError): """Raised if an argument is generally supplied but the use of the argument
was incorrect. This isfor instance raised if the number of values for an argument isnot correct.
.. versionadded:: 6.0 """
class FileError(ClickException): """Raised if a file cannot be opened."""
def __init__(self, filename: str, hint: t.Optional[str] = None) -> None: if hint isNone:
hint = _("unknown error")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.