2013-05-31 14 views
17

私が作業しているモジュールの例ではdocoptを使用していますが、すべてのオプションのデフォルト値は1を除いて動作しています。問題を特定しようとしているオプションを含むコードをすべて修正しましたが、デフォルト値は使用されません。なぜ私のdocoptオプションはデフォルト値を持っていませんか?

私のオプション・ブロックは、次のようになります。

Options: 
    --help      Show this message and exit 
    --version     Show version info and exit 
    -w WIDTH --width=WIDTH  The out to out width of the deck (feet) [default: 73] 
    -g GIRDERS --girders=GIRDERS The number of girders [default: 8] 
    -h HEIGHT --height=HEIGHT The height of the girders (inches) [default: 56] 
    -t THICK --thick=THICK  The deck thickness (inches) [default: 8] 
    -a ADIM --adim=ADIM   The "A" dimension, max deck thick @ CL girder [default: 12] 
    -l LSLP --leftslope=LSLP  The left-hand deck slope (ft/ft) [default: -0.02] 
    -r RSLP --rightslope=RSLP The right-hand deck slope (ft/ft) [default: -0.02] 
    -c --center     Indicates pivot point is at center of bridge 
    -o OFFSET --offset=OFFSET The offset of pivot point from center [default: 0] 

girdersオプションはデフォルト値を持っていることはありません!

私は数回this questionを再読しましたが、無関係です。

+10

私の推測:各オプションの説明の前に少なくとも* 2 *スペースが必要です – jfs

+1

私の推測も - 同じ問題がありました。http://stackoverflow.com/questions/13995352/why-are-defaults-notコマンドライン引数の辞書からのdocop/20283560#20283560 – hargriffle

答えて

24

他の質問の提案に従って、私はdocoptリポジトリをクローンし、現在のtipをゼロ効果でインストールしました。私はいくつかのデバッグを行い、問題を見つけることができるかどうかを確認することにしましたが、ソースコードがありました。オプションクラスの解析方法におけるライン200上

は、デフォルト値を取得するために使用される正規表現である:

matched = re.findall('\[default: (.*)\]', description, flags=re.I)

Iはdescription VARS値であることがわかっ周囲変数の束を印刷した後空の文字列。

options, _, description = option_description.strip().partition(' ')

私の目を引いた部分は、このでした:.partition(' ')、それは二つの空間だ。ここの説明を設定する行です。だから、私のコードを更新した後に成功し、私は戻ってドキュメントに向かうと「スペース」を検索:https://github.com/docopt/docopt#option-descriptions-format第六弾:

TL「彼らの非公式の説明でオプションを区切るには空白を2つ使用してください」; DR RTFM(または少なくともコード)。

ボーナス先端:docoptは、複数行の記述を理解し、あなたはちょうど80文字ラインを越え何でもラップすることができます:それほど読みやすい

Options: 
    --help      Show this message and exit 
    --version      Show version info and exit 
    -w WIDTH --width=WIDTH  The out to out width of the deck (feet) 
           [default: 73] 
    -g GIRDERS --girders=GIRDERS The number of girders [default: 8] 
    -h HEIGHT --height=HEIGHT  The height of the girders (inches) 
           [default: 56] 
    -t THICK --thick=THICK  The deck thickness (inches) [default: 8] 
    -a ADIM --adim=ADIM   The "A" dimension, max. deck thickness at 
           centerline of girder (inches) [default: 12] 
    -l LSLP --leftslope=LSLP  The left-hand deck slope (ft/ft) 
           [default: -0.02] 
    -r RSLP --rightslope=RSLP  The right-hand deck slope (ft/ft) 
           [default: -0.02] 
    -c --center     Indicates pivot point is at center of bridge 
    -o OFFSET --offset=OFFSET  The offset of pivot point from center 
           [default: 0] 

ないが、しかし正確に解析します。

関連する問題