Bug 1546718 - [tryselect] Add ability to post-filter fuzzy presets interactively, r=jgraham

Differential Revision: https://phabricator.services.mozilla.com/D28713

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Halberstadt 2019-04-24 19:36:03 +00:00
Родитель 33dc6347a7
Коммит 165e3bd55b
3 изменённых файлов: 40 добавлений и 6 удалений

Просмотреть файл

@ -96,13 +96,36 @@ If instead you want the intersection of queries, you can pass in ``-x/--and``:
# selects all windows mochitest tasks
$ mach try fuzzy --and -q "mochitest" -q "windows"
Using query intersections is especially useful with presets:
Modifying Presets
~~~~~~~~~~~~~~~~~
:doc:`Presets <../presets>` make it easy to run a pre-determined set of tasks. But sometimes you
might not want to run that set exactly as is, you may only want to use the preset as a starting
point then add or remove tasks as needed. This can be accomplished with ``-q/--query`` or
``-i/--interactive``.
Here are some examples of adding tasks to a preset:
.. code-block:: shell
# selects all windows perf tasks
# selects all perf tasks plus all mochitest-chrome tasks
$ mach try fuzzy --preset perf -q "mochitest-chrome"
# adds tasks to the perf preset interactively
$ mach try fuzzy --preset perf -i
Similarly, ``-x/--and`` can be used to filter down a preset by taking the intersection of the two
sets:
.. code-block:: shell
# limits perf tasks to windows only
$ mach try fuzzy --preset perf -xq "windows"
# limits perf tasks interactively
$ mach try fuzzy --preset perf -xi
Shell Conflicts
~~~~~~~~~~~~~~~

Просмотреть файл

@ -255,6 +255,9 @@ class TrySelect(MachCommandBase):
^start 'exact | !ignore fuzzy end$
"""
if kwargs.pop('interactive'):
kwargs['query'].append('INTERACTIVE')
if kwargs.pop('intersection'):
kwargs['intersect_query'] = kwargs['query']
del kwargs['query']

Просмотреть файл

@ -87,11 +87,18 @@ class FuzzyParser(BaseTryParser):
[['-q', '--query'],
{'metavar': 'STR',
'action': 'append',
'default': [],
'help': "Use the given query instead of entering the selection "
"interface. Equivalent to typing <query><ctrl-a><enter> "
"from the interface. Specifying multiple times schedules "
"the union of computed tasks.",
}],
[['-i', '--interactive'],
{'action': 'store_true',
'default': False,
'help': "Force running fzf interactively even when using presets or "
"queries with -q/--query."
}],
[['-x', '--and'],
{'dest': 'intersection',
'action': 'store_true',
@ -250,12 +257,12 @@ def run(update=False, query=None, intersect_query=None, templates=None, full=Fal
selected = set()
queries = []
def get_tasks(query_arg=None):
def get_tasks(query_arg=None, candidate_tasks=all_tasks):
cmd = base_cmd[:]
if query_arg:
if query_arg and query_arg != 'INTERACTIVE':
cmd.extend(['-f', query_arg])
query_str, tasks = run_fzf(cmd, all_tasks)
query_str, tasks = run_fzf(cmd, sorted(candidate_tasks))
queries.append(query_str)
return set(tasks)
@ -263,10 +270,11 @@ def run(update=False, query=None, intersect_query=None, templates=None, full=Fal
selected |= get_tasks(q)
for q in intersect_query or []:
tasks = get_tasks(q)
if not selected:
tasks = get_tasks(q)
selected |= tasks
else:
tasks = get_tasks(q, selected)
selected &= tasks
if not queries: