python argparse with dependencies

后端 未结 2 2239
醉话见心
醉话见心 2021-02-19 21:25

I\'m writing a script which has 2 arguments which are mutually exclusive, and an option that only makes sense with one of those arguments. I\'m trying to set up argparse to fail

2条回答
  •  故里飘歌
    2021-02-19 21:58

    Add the usage argument when creating the parser:

    usage = "usage: whichboom [-h] [-s | [-h] [-s]] host"
    description = "Lookup servers by ip address from host file"
    parser = argparse.ArgumentParser(description=description, usage=usage)
    

    Source: http://docs.python.org/dev/library/argparse.html#usage

提交回复
热议问题