Skip to content

Commit

Permalink
Pass ctx to NoSuchOption exceptions
Browse files Browse the repository at this point in the history
Ensures that exception printing hints about using ``--help`` option.
  • Loading branch information
Garrett Smith authored and sirosen committed Aug 31, 2018
1 parent 123dd71 commit 14a9341
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -8,6 +8,8 @@ Version 7.0

(upcoming release with new features, release date to be decided)

- ``NoSuchOption`` errors take ``ctx`` so that ``--help`` hint gets printed in
error output (`#860`_)
- Non-standalone calls to Context.exit return the exit code, rather than
calling ``sys.exit`` (`#667`_)(`#533`_)
- Updated test env matrix. (`#1027`_)
Expand Down
4 changes: 2 additions & 2 deletions click/parser.py
Expand Up @@ -321,7 +321,7 @@ def _match_long_opt(self, opt, explicit_value, state):
if opt not in self._long_opt:
possibilities = [word for word in self._long_opt
if word.startswith(opt)]
raise NoSuchOption(opt, possibilities=possibilities)
raise NoSuchOption(opt, possibilities=possibilities, ctx=self.ctx)

option = self._long_opt[opt]
if option.takes_value:
Expand Down Expand Up @@ -364,7 +364,7 @@ def _match_short_opt(self, arg, state):
if self.ignore_unknown_options:
unknown_options.append(ch)
continue
raise NoSuchOption(opt)
raise NoSuchOption(opt, ctx=self.ctx)
if option.takes_value:
# Any characters left in arg? Pretend they're the
# next arg, and stop consuming characters of arg.
Expand Down

0 comments on commit 14a9341

Please sign in to comment.