シンプルな CLI を作成するために docopt を使用しようとしてきましたが、何らかの理由で既定のパラメーターが表示されません。以下は私のテストコードです。docopt.py
github リポジトリの最新バージョンを使用しています。
"""
Usage: scrappy <path> ... [options]
-a --auto Automatically scrape and rename without user interaction.
-l --lang Specify language code [default: en].
--scan-individual Evaluate series information individually for each file.
-c --cfg User alternate config file [default: ../scrappy.conf]
-t --test Test run. Do not modify files.
-v --verbose Print verbose output
"""
from docopt import docopt
arguments = docopt(__doc__, version='0.1.0 alpha')
print arguments # DEBUG
実行したときの出力は次のとおりです$ scrappy/scrappy.py first_path_parameter second/path/parameter
{'--auto': None,
'--cfg': None,
'--lang': None,
'--scan-individual': None,
'--test': None,
'--verbose': None,
'<path>': ['first_path_parameter', 'second/path/parameter']}
何が起こっているか知っている人はいますか?
編集:
コードを更新しましたが、まだ同様の出力が得られます。さらに、 を渡そうと--scan-individual
すると、引数が必要であるというエラーが表示されます。繰り返しになりますが、問題が発生した場合に備えて、docopt.py をプロジェクトの作業ディレクトリにコピーするだけで docopt を実行しています。何が起きてる?
#!/usr/bin/env python
"""Scrappy: Rename media files based on scraped information.
Usage: scrappy <path> ... [options]
-a --auto Automatically scrape and rename without user interaction.
-l LANG --lang LANG Specify language code [default: en].
--scan-individual Evaluate series information individually for each file.
-c CONF --cfg CONF User alternate config file [default: ../scrappy.conf]
-t --test Test run. Do not modify files.
-v --verbose Print verbose output
"""
from docopt import docopt
arguments = docopt(__doc__, version='0.1.0 alpha')
print arguments # DEBUG
出力:
$ scrappy/scrappy.py first_path_parameter second/path/parameter --scan-individual
--scan-individual requires argument
Usage: scrappy <path> ... [options]