tools: allow alternative spellings of target name (ESP32-S2, ESP32S2)

by ignoring character case and hyphens in target name.
This commit is contained in:
Ivan Grokhotkov
2020-04-03 16:21:24 +02:00
parent 4d53c137e6
commit 7b79b52062
3 changed files with 32 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import click
import os
import re
import subprocess
@@ -314,3 +315,25 @@ def _guess_or_check_idf_target(args, prog_name, cache):
"To keep the setting in sdkconfig ({t_conf}) and re-generate CMakeCache.txt, run '{prog} fullclean'. "
"To re-generate sdkconfig for '{t_cache}' target, run '{prog} set-target {t_cache}'."
.format(t_conf=idf_target_from_sdkconfig, t_cache=idf_target_from_cache, prog=prog_name))
class TargetChoice(click.Choice):
"""
A version of click.Choice with two special features:
- ignores hyphens
- not case sensitive
"""
def __init__(self, choices):
super(TargetChoice, self).__init__(choices, case_sensitive=False)
def convert(self, value, param, ctx):
def normalize(str):
return str.lower().replace("-", "")
saved_token_normalize_func = ctx.token_normalize_func
ctx.token_normalize_func = normalize
try:
return super(TargetChoice, self).convert(value, param, ctx)
finally:
ctx.token_normalize_func = saved_token_normalize_func