Commit 83b9577f authored by Luca Burelli's avatar Luca Burelli Committed by Chris Friedt
Browse files

west build: display closest matching board names on error



This commit modifies the 'west build' command to display the closest
matching boards when an invalid board is specified, making it easier
for users to find a typo in the used board name.

The user is also instructed to run 'west boards' if he wants to get
the full list of available boards.

Signed-off-by: default avatarLuca Burelli <l.burelli@arduino.cc>
parent bf3eba1c
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -218,10 +218,9 @@ elseif(BOARD_DIR)
	  "Please run a pristine build."
  )
else()
  message("No board named '${BOARD}' found.\n\n"
          "Please choose one of the following boards:\n"
  )
  execute_process(${list_boards_commands})
  message("No board named '${BOARD}' found. Did you mean:\n")
  execute_process(${list_boards_commands} --fuzzy-match ${BOARD})
  message("\nRun 'west boards' for the full list.")
  unset(CACHED_BOARD CACHE)
  message(FATAL_ERROR "Invalid BOARD; see above.")
endif()
+12 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
# SPDX-License-Identifier: Apache-2.0

import argparse
import difflib
import itertools
import sys
from collections import Counter, defaultdict
@@ -372,7 +373,9 @@ def add_args(parser):
    parser.add_argument("--board", dest='board', default=None,
                        help='lookup the specific board, fail if not found')
    parser.add_argument("--board-dir", default=[], type=Path, action='append',
                        help='Only look for boards at the specific location')
                        help='only look for boards at the specific location')
    parser.add_argument("--fuzzy-match", default=None,
                        help='lookup boards similar to the given board name')


def add_args_formatting(parser):
@@ -414,6 +417,9 @@ def board_v2_qualifiers_csv(board):

def dump_v2_boards(args):
    boards = find_v2_boards(args)
    if args.fuzzy_match is not None:
        close_boards = difflib.get_close_matches(args.fuzzy_match, boards.keys())
        boards = {b: boards[b] for b in close_boards}

    for b in boards.values():
        qualifiers_list = board_v2_qualifiers(b)
@@ -442,6 +448,11 @@ def dump_v2_boards(args):
def dump_boards(args):
    arch2boards = find_arch2boards(args)
    for arch, boards in arch2boards.items():
        if args.fuzzy_match is not None:
            close_boards = difflib.get_close_matches(args.fuzzy_match, [b.name for b in boards])
            if not close_boards:
                continue
            boards = [b for b in boards if b.name in close_boards]
        if args.cmakeformat is None:
            print(f'{arch}:')
        for board in boards: