65a8a5ff69289a5cb8fce6555b774573e4452a79
- Author
- Ryan <fauxpark@gmail.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/docs/cli_commands.md b/docs/cli_commands.md
2index 7d74d8e6177b384c5437c5ab21919948b04df151..4cd5ae98c3905f05173945b3b2e67c8062eeaaf1 100644
3--- a/docs/cli_commands.md
4+++ b/docs/cli_commands.md
5@@ -153,20 +153,26 @@ qmk cd
6
7diff --git a/lib/python/qmk/search.py b/lib/python/qmk/search.py
8index 6517bb4951d62f6cebfc1a91bdf983f3035c3258..c7bce344ad19f7204dbe607e1275f6f695697ccf 100644
9--- a/lib/python/qmk/search.py
10+++ b/lib/python/qmk/search.py
11@@ -239,11 +239,11 @@ def _filter_keymap_targets(target_list: List[KeyboardKeymapDesc], filters: List[
12 valid_targets = parallel_map(_load_keymap_info, target_list)
13
14 function_re = re.compile(r'^(?P<function>[a-zA-Z]+)\((?P<key>[a-zA-Z0-9_\.]+)(,\s*(?P<value>[^#]+))?\)$')
15- equals_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*=\s*(?P<value>[^#]+)$')
16+ comparison_re = re.compile(r'^(?P<key>[a-zA-Z0-9_\.]+)\s*(?P<op>[\<\>\!=]=|\<|\>)\s*(?P<value>[^#]+)$')
17
18 for filter_expr in filters:
19 function_match = function_re.match(filter_expr)
20- equals_match = equals_re.match(filter_expr)
21+ comparison_match = comparison_re.match(filter_expr)
22
23 if function_match is not None:
24 func_name = function_match.group('function').lower()
25@@ -259,23 +259,43 @@ def _filter_keymap_targets(target_list: List[KeyboardKeymapDesc], filters: List[
26 value_str = f", {{fg_cyan}}{value}{{fg_reset}}" if value is not None else ""
27 cli.log.info(f'Filtering on condition: {{fg_green}}{func_name}{{fg_reset}}({{fg_cyan}}{key}{{fg_reset}}{value_str})...')
28
29- elif equals_match is not None:
30- key = equals_match.group('key')
31- value = equals_match.group('value')
32- cli.log.info(f'Filtering on condition: {{fg_cyan}}{key}{{fg_reset}} == {{fg_cyan}}{value}{{fg_reset}}...')
33+ elif comparison_match is not None:
34+ key = comparison_match.group('key')
35+ op = comparison_match.group('op')
36+ value = comparison_match.group('value')
37+ cli.log.info(f'Filtering on condition: {{fg_cyan}}{key}{{fg_reset}} {op} {{fg_cyan}}{value}{{fg_reset}}...')
38
39- def _make_filter(k, v):
40+ def _make_filter(k, o, v):
41 expr = fnmatch.translate(v)
42 rule = re.compile(f'^{expr}$', re.IGNORECASE)
43
44 def f(e: KeyboardKeymapDesc):
45 lhs = e.dotty.get(k)
46- lhs = str(False if lhs is None else lhs)
47- return rule.search(lhs) is not None
48+ rhs = v
49+
50+ if o in ['<', '>', '<=', '>=']:
51+ lhs = int(False if lhs is None else lhs)
52+ rhs = int(rhs)
53+
54+ if o == '<':
55+ return lhs < rhs
56+ elif o == '>':
57+ return lhs > rhs
58+ elif o == '<=':
59+ return lhs <= rhs
60+ elif o == '>=':
61+ return lhs >= rhs
62+ else:
63+ lhs = str(False if lhs is None else lhs)
64+
65+ if o == '!=':
66+ return rule.search(lhs) is None
67+ elif o == '==':
68+ return rule.search(lhs) is not None
69
70 return f
71
72- valid_targets = filter(_make_filter(key, value), valid_targets)
73+ valid_targets = filter(_make_filter(key, op, value), valid_targets)
74 else:
75 cli.log.warning(f'Unrecognized filter expression: {filter_expr}')
76 continue
77diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
78index f18bd12f8201582272f0d08a0b0585543fd30132..b10fd8d19d50ecd763faaf6156b977687e4e4dbd 100644
79--- a/lib/python/qmk/tests/test_cli_commands.py
80+++ b/lib/python/qmk/tests/test_cli_commands.py
81@@ -390,7 +390,7 @@ def test_find_contains():
82 def test_find_multiple_conditions():
83 # this is intended to match at least 'crkbd/rev1'
84 result = check_subcommand(