开发者

Printing linux man-help like on python

开发者 https://www.devze.com 2023-02-13 15:38 出处:网络
I am trying to build a help message output for my custom app like Linux man does. I\'ve been walking around pprint, using dictionaries, and others. But, I\'m al little lost. I\'m currently using a dic

I am trying to build a help message output for my custom app like Linux man does. I've been walking around pprint, using dictionaries, and others. But, I'm al little lost. I'm currently using a dictionary combined with print commands. Until now开发者_运维百科 is enough for my needs but I must confess It's not up to scratch.

I would like to use the flags command style, I mean, -f , -t , etc. I supose that the point of establish is to extract data using a parser o something like that.

So, in a few words, How do you guys build help messages for the properly usage of your command based apps?


optparse and argparse both support printing usage details.


There's the optparse module, and its successor argparse (the first one is deprecated since Python 2.7). These modules automatically generate help output like this one (from the Python docs):

$ prog.py -h
usage: prog.py [-h] [--sum] N [N ...]

Process some integers.

positional arguments:
 N           an integer for the accumulator

optional arguments:
 -h, --help  show this help message and exit
 --sum       sum the integers (default: find the max)
0

精彩评论

暂无评论...
验证码 换一张
取 消