Skip to content
Myr

Implemented NoSuchOption and BadOptionUsage exceptions.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 563017b · Browse files · 2 files+40 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+40 added−2 removed

  • other:+40 added−2 removed

2 files+40 added−2 removed

modified:click/__init__.py+2 added-2 removed
36 unmodified lines
37 pause3839# Exceptions40from .exceptions import ClickException, UsageError, BadParameter, \41 FileError, Abort41 FileError, Abort, NoSuchOption, BadOptionUsage4243# Formatting44from .formatting import HelpFormatter, wrap_text45
25 unmodified lines
71 'getchar', 'pause',7273 # Exceptions74 'ClickException', 'UsageError', 'BadParameter', 'FileError',75 'Abort',75 'Abort', 'NoSuchOption', 'BadOptionUsage',7677 # Formatting78 'HelpFormatter', 'wrap_text',79
6 unmodified lines
modified:click/exceptions.py+38 added
82 unmodified lines
83 param_hint = ' / '.join('"%s"' % x for x in param_hint)84 return 'Invalid value for %s: %s' % (param_hint, self.message)858687class NoSuchOption(UsageError):88 """Raised if click attempted to handle an option that does not89 exist.9091 .. versionadded:: 4.092 """9394 def __init__(self, option_name, message=None, possibilities=None,95 ctx=None):96 if message is None:97 message = 'no such option: %s' % option_name98 UsageError.__init__(self, message, ctx)99 self.option_name = option_name100 self.possibilities = possibilities101102 def format_message(self):103 bits = [self.message]104 if self.possibilities:105 if len(self.possibilities) == 1:106 bits.append('Did you mean %s?' % self.possibilities[0])107 else:108 possibilities = sorted(self.possibilities)109 bits.append('(Possible options: %s)' % ', '.join(possibilities))110 return ' '.join(bits)111112113class BadOptionUsage(UsageError):114 """Raised if an option is generally supplied but the use of the option115 was incorrect. This is for instance raised if the number of arguments116 for an option is not correct.117118 .. versionadded:: 4.0119 """120121 def __init__(self, option_name, message, ctx=None):122 UsageError.__init__(self, message, ctx)123124125class FileError(ClickException):126 """Raised if a file cannot be opened."""127128 def __init__(self, filename, hint=None):
13 unmodified lines