I would like to be able in my program to support several short-form arguments like ‘-c’ and -ct’. The problem is that for short-form arguments, argparse has the ability to join them, so it considers that ‘-ct’ is in fact ‘-c’ and ‘-t’, which is NOT what I want and could produce weird bugs (since I also have a separate ‘-t’ argument).
Here’s my code:
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--default-config', type=str, nargs=1, required=False)
parser.add_argument('-ct', '--countdown', type=str, nargs=1, required=False)
But if I remove the short-forms, the long-forms work perfectly well.
From the argparse doc:
http://docs.python.org/dev/library/argparse.html#option-value-syntax
http://docs.python.org/dev/library/argparse.html#argument-abbreviations
Do someone know how to disable joining and/or abbreviation of the short-form parameters?
I believe convention dictates that “short” arguments are only a single character and they may be combined into a single word on the command line so that “-ct” is equivalent to “-c -t”. My guess is that argparse doesn’t support two-char “short” arguments like “-ct” so behavior is undefined.