Is there a way to make an argument strictly used alone, without other flags, or it throws an error?
import argparse
parser = argparse.ArgumentParser(description='description')
parser.add_argument("-n", "--line-number", help="print line numbers", action="store_true")
parser.add_argument("-e", "--errors", action="store_true", help="errors")
parser.add_argument("--debug", action="store_true", help="debug")
So for example in the code above, I want --debug
to be used alone. If there are any other flags it would throw an error, but the -n
and -e
flag can still be used together like in the example below.
$ python3 file.py --debug // It works
$ python3 file.py --debug -n -e // Error: --debug can only be used alone...
$ python3 file.py -n -e // Work together
$ python3 file.py -n // or alone
I've tried using groups and reading the documentation but I haven't found anything useful.
How can I implement this behavior?