diff options
author | Wolfgang Müller | 2021-05-01 16:14:49 +0200 |
---|---|---|
committer | Wolfgang Müller | 2021-05-01 17:41:47 +0200 |
commit | c69598f4f8deb98071c9908f84efba94a1a02321 (patch) | |
tree | 0e6bdfd292fc09c397998be03e22d29e9d2e8549 | |
parent | c4f5dbab6e377fe7ee6040c3d5038157b58db621 (diff) | |
download | quarg-c69598f4f8deb98071c9908f84efba94a1a02321.tar.gz |
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.
Diffstat (limited to '')
-rw-r--r-- | quarg/actions.py | 4 |
1 files changed, 3 insertions, 1 deletions
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]) |