|
4 | 4 | # SPDX-License-Identifier: Apache-2.0 |
5 | 5 |
|
6 | 6 | import argparse |
| 7 | +import difflib |
7 | 8 | import itertools |
8 | 9 | import sys |
9 | 10 | from collections import Counter, defaultdict |
@@ -372,7 +373,9 @@ def add_args(parser): |
372 | 373 | parser.add_argument("--board", dest='board', default=None, |
373 | 374 | help='lookup the specific board, fail if not found') |
374 | 375 | parser.add_argument("--board-dir", default=[], type=Path, action='append', |
375 | | - help='Only look for boards at the specific location') |
| 376 | + help='only look for boards at the specific location') |
| 377 | + parser.add_argument("--fuzzy-match", default=None, |
| 378 | + help='lookup boards similar to the given board name') |
376 | 379 |
|
377 | 380 |
|
378 | 381 | def add_args_formatting(parser): |
@@ -414,6 +417,9 @@ def board_v2_qualifiers_csv(board): |
414 | 417 |
|
415 | 418 | def dump_v2_boards(args): |
416 | 419 | boards = find_v2_boards(args) |
| 420 | + if args.fuzzy_match is not None: |
| 421 | + close_boards = difflib.get_close_matches(args.fuzzy_match, boards.keys()) |
| 422 | + boards = {b: boards[b] for b in close_boards} |
417 | 423 |
|
418 | 424 | for b in boards.values(): |
419 | 425 | qualifiers_list = board_v2_qualifiers(b) |
@@ -442,6 +448,11 @@ def notfound(x): |
442 | 448 | def dump_boards(args): |
443 | 449 | arch2boards = find_arch2boards(args) |
444 | 450 | for arch, boards in arch2boards.items(): |
| 451 | + if args.fuzzy_match is not None: |
| 452 | + close_boards = difflib.get_close_matches(args.fuzzy_match, [b.name for b in boards]) |
| 453 | + if not close_boards: |
| 454 | + continue |
| 455 | + boards = [b for b in boards if b.name in close_boards] |
445 | 456 | if args.cmakeformat is None: |
446 | 457 | print(f'{arch}:') |
447 | 458 | for board in boards: |
|
0 commit comments