1

Is there a way in argparse to print my help, not auto-generated, for --help,
but only the short help= for single options ? An example:

    # my help, not auto-generated --
if len(sys.argv) >= 1  and sys.argv[1].startswith(( "-h", "--h" )):
    print __doc__
    sys.exit()

p = argparse.ArgumentParser( usage="" )

    # want to print only this short help= for e.g. `-help -col`
p.add_argument( "-col", default=1, type=int,
                        help="the column to look at and color, 1 2 3 ..." )

    # and only this help= for e.g. `-help -color`
p.add_argument( "-color", "-colour", default="red",
                        help="one of: r g b red green blue " )

~

denis
  • 21,378
  • 10
  • 65
  • 88
  • What's the difference between your expected help message and the message generated by argparse? – Edgar Andrés Margffoy Tuay Apr 21 '17 at 14:19
  • 1
    Capturing the `help` right away is a good idea. `ipython` does that. And this way lets you distinguish between `-h` and `--help`. Doing this within `argparse` is possible but would be a lot more work. – hpaulj Apr 21 '17 at 16:23
  • @Edgar Andrés Margffoy Tuay, mine is longer, has examples, what I want to convey to users -- ideally, a `man` page. – denis Apr 21 '17 at 16:25
  • I don't know if implementing an instance of ``argparse.HelpFormatter`` might be of help: http://stackoverflow.com/questions/3853722/python-argparse-how-to-insert-newline-in-the-help-text – Edgar Andrés Margffoy Tuay Apr 22 '17 at 01:53

0 Answers0