Extend argparse to write set names in the help text for optional argument choices and define those sets once at the end
- by Kent
Example of the problem
If I have a list of valid option strings which is shared between several arguments, the list is written in multiple places in the help string. Making it harder to read:
def main():
elements = ['a', 'b', 'c', 'd', 'e', 'f']
parser = argparse.ArgumentParser()
parser.add_argument(
'-i',
nargs='*',
…