Skip to content

Commit

Permalink
Fix and changelog closes #793
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Sep 30, 2022
1 parent 983fcc9 commit 0a5b404
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 1 addition & 4 deletions invoke/completion/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
from ..util import debug, task_name_sort_key


def complete(names, core, initial_context, collection):
def complete(names, core, initial_context, collection, parser):
# Strip out program name (scripts give us full command line)
# TODO: this may not handle path/to/script though?
invocation = re.sub(r"^({}) ".format("|".join(names)), "", core.remainder)
debug("Completing for invocation: {!r}".format(invocation))
# Tokenize (shlex will have to do)
tokens = shlex.split(invocation)
# Make ourselves a parser (can't just reuse original one as it's mutated /
# been overwritten)
parser = Parser(initial=initial_context, contexts=collection.to_contexts())
# Handle flags (partial or otherwise)
if tokens and tokens[-1].startswith("-"):
tail = tokens[-1]
Expand Down
20 changes: 14 additions & 6 deletions invoke/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ def parse_cleanup(self):
core=self.core,
initial_context=self.initial_context,
collection=self.collection,
# NOTE: can't reuse self.parser as it has likely been mutated
# between when it was set and now.
parser=self._make_parser(),
)

# Fallback behavior if no tasks were given & no default specified
Expand Down Expand Up @@ -717,6 +720,16 @@ def _update_core_context(self, context, new_args):
if arg.got_value:
context.args[key]._value = arg._value


def _make_parser(self):
return Parser(
initial=self.initial_context,
contexts=self.collection.to_contexts(
ignore_unknown_help=self.config.tasks.ignore_unknown_help
),
)


def parse_tasks(self):
"""
Parse leftover args, which are typically tasks & per-task args.
Expand All @@ -731,12 +744,7 @@ def parse_tasks(self):
.. versionadded:: 1.0
"""
self.parser = Parser(
initial=self.initial_context,
contexts=self.collection.to_contexts(
ignore_unknown_help=self.config.tasks.ignore_unknown_help
),
)
self.parser = self._make_parser()
debug("Parsing tasks against {!r}".format(self.collection))
result = self.parser.parse_argv(self.core.unparsed)
self.core_via_tasks = result.pop(0)
Expand Down
3 changes: 3 additions & 0 deletions sites/www/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Changelog
=========

- :bug:`793` Refactor CLI parser instantiation such that the
``tasks.ignore_unknown_help`` feature (added in 1.7) works when Invoke is run
in ``--complete`` mode, i.e. in tab-completion scripts.
- :bug:`-` Fix errors thrown when comparing `~invoke.tasks.Task` objects to
non-Task objects; such comparisons are now always false.
- :release:`1.7.1 <2022-05-11>`
Expand Down

0 comments on commit 0a5b404

Please sign in to comment.