Python ArgumentParser nested arguments
I want to create argument parser with following signature: ./myapp [-a [-b BVAL] | -c] In other words, user could provide argument -b BVAL only in case if he provided argument -a . It's quite easy to create mutually exclusive group of -a and -c , but I can't figure out how to create relationship allow -b only if -a provided You could inherit from ArgumentParser to add some custom functionality. Here I am raising an exception, but you could modify this to implement whatever you would like. Just change the on_dependency_error() method to suit your needs. from argparse import ArgumentParser class