From c69598f4f8deb98071c9908f84efba94a1a02321 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Sat, 1 May 2021 16:14:49 +0200 Subject: actions: Have ParseEnum print a list of possible values on error This will save the user a look at the program's manual and makes using the program more convenient. --- quarg/actions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/quarg/actions.py b/quarg/actions.py index 9361ac2..70cde03 100644 --- a/quarg/actions.py +++ b/quarg/actions.py @@ -13,7 +13,9 @@ class ParseEnum(argparse.Action, metaclass=ABCMeta): def __call__(self, parser, namespace, value, option_string=None): key = value.upper() if key not in self.enumclass.__members__: - errx(f'Not a valid {self.enumclass.describe()}: {value}') + possible = ', '.join([e.name.lower() for e in self.enumclass]) + desc = self.enumclass.describe() + errx(f'Not a valid {desc}: {value}\nPossible {desc}s are: {possible}') saved = getattr(namespace, self.dest) or [] saved.append(self.enumclass[key]) -- cgit v1.2.3-2-gb3c3