0

I am using argparse and this code

parser = argparse.ArgumentParser()
parser.add_argument('-c', '--client', nargs='*', action='store', help='Client mode, connect to [ hostname/address or localhost | port or 8080 | protocol or TCP ]')

shows this on help page

  -c [CLIENT [CLIENT ...]], --client [CLIENT [CLIENT ...]]
                        Client mode, connect to [ hostname/address or
                        localhost | port or 8080 | protocol or TCP ]

How can I make it more like following?

  -c [host [port]], --client [host [port]]
                        Client mode, connect to [ hostname/address or
                        localhost | port or 8080 | protocol or TCP ]
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
ArekBulski
  • 4,520
  • 4
  • 39
  • 61
  • So you want to allow any number of clients, each of which can have up to three parameters? – jonrsharpe Jun 24 '17 at 20:48
  • I not sure why this was closed or why the `duplicate` answers it. What was your problem? I was going to suggest `metavar=('host','port')` to refine the labeling. But if you don't like the open ended `*`, there's not much you can do. There isn't an `nargs` to restrict the input to a [0,1,2] range. I can reopen this if you refine your question. – hpaulj Jun 24 '17 at 21:09
  • `metavar` seems to be what I was asking. Thank you guys. – ArekBulski Jun 25 '17 at 00:16

0 Answers0