mirror of https://github.com/ARMmbed/mbed-os.git
Force conversion of all -i, -m, -t to the correct case
parent
6fda53b8b8
commit
5052e97b17
|
@ -17,8 +17,7 @@ limitations under the License.
|
|||
from argparse import ArgumentParser
|
||||
from tools.toolchains import TOOLCHAINS
|
||||
from tools.targets import TARGET_NAMES
|
||||
from utils import argparse_uppercase_type, argparse_lowercase_hyphen_type, argparse_many
|
||||
|
||||
from utils import argparse_force_uppercase_type, argparse_lowercase_hyphen_type, argparse_many
|
||||
|
||||
def get_default_options_parser(add_clean=True, add_options=True):
|
||||
parser = ArgumentParser()
|
||||
|
@ -31,12 +30,12 @@ def get_default_options_parser(add_clean=True, add_options=True):
|
|||
parser.add_argument("-m", "--mcu",
|
||||
help="build for the given MCU (%s)" % ', '.join(targetnames),
|
||||
metavar="MCU",
|
||||
type=argparse_many(argparse_uppercase_type(targetnames, "MCU")))
|
||||
type=argparse_many(argparse_force_uppercase_type(targetnames, "MCU")))
|
||||
|
||||
parser.add_argument("-t", "--tool",
|
||||
help="build using the given TOOLCHAIN (%s)" % ', '.join(toolchainlist),
|
||||
metavar="TOOLCHAIN",
|
||||
type=argparse_many(argparse_uppercase_type(toolchainlist, "toolchain")))
|
||||
type=argparse_many(argparse_force_uppercase_type(toolchainlist, "toolchain")))
|
||||
|
||||
if add_clean:
|
||||
parser.add_argument("-c", "--clean", action="store_true", default=False,
|
||||
|
|
|
@ -16,6 +16,7 @@ from tools.tests import test_known, test_name_known
|
|||
from tools.targets import TARGET_NAMES
|
||||
from tools.libraries import LIBRARIES
|
||||
from utils import argparse_lowercase_type, argparse_uppercase_type, argparse_filestring_type, argparse_many
|
||||
from utils import argparse_force_lowercase_type, argparse_force_uppercase_type
|
||||
|
||||
|
||||
|
||||
|
@ -32,14 +33,14 @@ if __name__ == '__main__':
|
|||
metavar="MCU",
|
||||
default='LPC1768',
|
||||
required=True,
|
||||
type=argparse_many(argparse_uppercase_type(targetnames, "MCU")),
|
||||
type=argparse_many(argparse_force_uppercase_type(targetnames, "MCU")),
|
||||
help="generate project for the given MCU (%s)"% ', '.join(targetnames))
|
||||
|
||||
parser.add_argument("-i",
|
||||
dest="ide",
|
||||
default='uvision',
|
||||
required=True,
|
||||
type=argparse_many(argparse_lowercase_type(toolchainlist, "toolchain")),
|
||||
type=argparse_many(argparse_force_lowercase_type(toolchainlist, "toolchain")),
|
||||
help="The target IDE: %s"% str(toolchainlist))
|
||||
|
||||
parser.add_argument("-c", "--clean",
|
||||
|
|
|
@ -223,6 +223,27 @@ argparse_lowercase_type = argparse_type(str.lower, False)
|
|||
argparse_uppercase_hyphen_type = argparse_type(str.upper, True)
|
||||
argparse_lowercase_hyphen_type = argparse_type(str.lower, True)
|
||||
|
||||
def argparse_force_type(case):
|
||||
def middle(list, type_name):
|
||||
# validate that an argument passed in (as string) is a member of the list of possible
|
||||
# arguments after converting it's case. Offer a suggestion if the hyphens/underscores
|
||||
# do not match the expected style of the argument.
|
||||
def parse_type(string):
|
||||
string = case(string)
|
||||
newstring = string.replace("-","_")
|
||||
if string in list:
|
||||
return string
|
||||
elif string not in list and newstring in list:
|
||||
raise argparse.ArgumentTypeError("{0} is not a supported {1}. Did you mean {2}?".format(string, type_name, newstring))
|
||||
else:
|
||||
raise argparse.ArgumentTypeError("{0} is not a supported {1}. Supported {1}s are:\n{2}".format(string, type_name, columnate(list)))
|
||||
return parse_type
|
||||
return middle
|
||||
|
||||
# these two types convert the case of their arguments _before_ validation
|
||||
argparse_force_uppercase_type = argparse_force_type(str.upper)
|
||||
argparse_force_lowercase_type = argparse_force_type(str.lower)
|
||||
|
||||
# An argument parser combinator that takes in an argument parser and creates a new parser that
|
||||
# accepts a comma separated list of the same thing.
|
||||
def argparse_many(fn):
|
||||
|
|
Loading…
Reference in New Issue