2013-05-31 1 views
17

내가 작업중인 모듈의 예제에서 docopt을 사용하고 있으며, 모든 옵션 기본값이 하나만 제외하고 작동하고 있습니다. 문제를 식별하려고 시도하는 옵션을 포함하고있는 모든 코드를 수정했지만 기본값은 사용하지 않습니다!내 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-my-command-line-argument-dictionary from docop/20283560 # 20283560 – hargriffle

답변

24

다른 질문에 대한 제안에 따라 docopt repo를 복제하고 현재 팁을 제로 효과로 설치했습니다. 이제 디버깅을하고 문제를 찾을 수 있는지 확인하기로 결정했지만 소스 코드가 생겼습니다. I는 description VARS 값이이었던 것으로

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

주변 변수의 무리를 인쇄 한 후 : 옵션 클래스의 해석 방법에서 라인 (200)상의

디폴트 값을 잡기 위해 이용되는 정규식 빈 문자열. 그 두 공간의, .partition(' ') : 내 눈이 있었다 잡은

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

부분 : 여기에 설명을 설정하는 라인이다. 그래서 내 코드를 업데이트 한 후 성공적으로 나는 다시 문서로 머리와 "공간"을 검색 : https://github.com/docopt/docopt#option-descriptions-format 여섯 번째 총알 :

TL "자신의 비공식적 인 설명과 함께 옵션을 구분하기 위해이 개 공간을 사용하여"; 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] 

하지,하지만 제대로 구문 분석합니다.