2012-02-01 16 views
3

私は、Pythonで書かれたユーティリティを持っています。これは、単独で、または他のシェルユーティリティと組み合わせて使用​​するためのものです。そのため、私のユーティリティは状態コードで終了します(例:0すべてが問題ない場合、入力ファイルまたは出力ディレクトリが存在しない場合は1など)。argparseの--helpが終了ステータスを表示することは可能ですか?

私の質問:私はargparse moduleを使用しています。これは、オプションの解析だけでなくヘルプの生成にも役立ちます。ただし、終了ステータスに関する情報をヘルプに追加することもできます。これはargparseで可能ですか?私は何かを欠いている?

+1

あなたは[エピローグ](http://docs.python.org/library/argparse.html#epilog)にその情報を入れて検討していますか? –

+0

@RikPoggi:あなたのコメントは答えになるはずです。 –

答えて

6

これは、私がepilogの中に入れた情報です。公式ドキュメントからの例を調整

>>> import argparse 
>>> parser = argparse.ArgumentParser(
...  description='This is my utility description.', 
...  epilog='The exit status will be 0 if everything is fine, ' 
...   'and 1 if an input-file or an output-directory does not exist') 
>>> 
>>> parser.print_help() 
usage: [-h] 

This is my utility description. 

optional arguments: 
    -h, --help show this help message and exit 

The exit status will be 0 if everything is fine, and 1 when an input-file or 
an output-directory does not exist 
+0

おかげで、それはまさに私がすべきことです! – JStroop

関連する問題