My application is a specialized file comparison utility and obviously it does not make sense to compare only one file, so nargs='+' is not quite appropriate.
nargs=N only excepts a maximum of N arguments, but I need to accept an infinite number of arguments as long as there are at least two of them.
Short answer is you can’t do that because nargs doesn’t support something like ‘2+’.
Long answer is you can workaround that using something like this:
The tricks that you need are:
usageto provide you own usage string to the parsermetavarto display an argument with a different name in the help stringSUPPRESSto avoid displaying help for one of the variablesNamespaceobject that the parser returnsThe example above produces the following help string:
and will still fail when less than two arguments are passed: