次のコードがあります。
parser = argparse.ArgumentParser(description='Postfix Queue Administration Tool',
prog='pqa',
usage='%(prog)s [-h] [-v,--version]')
parser.add_argument('-l', '--list', action='store_true',
help='Shows full overview of all queues')
parser.add_argument('-q', '--queue', action='store', metavar='<queue>', dest='queue',
help='Show information for <queue>')
parser.add_argument('-d', '--domain', action='store', metavar='<domain>', dest='domain',
help='Show information about a specific <domain>')
parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1')
args = parser.parse_args()
次のような出力が得られます。
%./pqa
usage: pqa [-h] [-v,--version]
Postfix Queue Administration Tool
optional arguments:
-h, --help show this help message and exit
-l, --list Shows full overview of all queues
-q <queue>, --queue <queue>
Show information for <queue>
-d <domain>, --domain <domain>
Show information about a specific <domain>
-v, --version show program's version number and exit
それぞれが metavar も表示する 2 つのバージョン (つまり、長いオプション) を持つコマンドを「グループ化」する方法を知りたいです。
これは主に私の側の審美的な問題ですが、それでも修正したいと思います。インターネットでマニュアルやテキストを読んでいますが、情報がそこにないか、ここに何かが完全に欠けています:)