【发布时间】:2015-02-09 06:04:35
【问题描述】:
我想完成这样的事情:
-LoadFiles
-SourceFile "" -DestPath ""
-SourceFolder "" -DestPath ""
-GenericOperation
-SpecificOperation -Arga "" -Argb ""
-OtherOperation -Argc "" -Argb "" -Argc ""
用户应该能够运行以下内容:
-LoadFiles -SourceFile "somePath" -DestPath "somePath"
或
-LoadFiles -SourceFolder "somePath" -DestPath "somePath"
基本上,如果您有-LoadFiles,则后面必须有-SourceFile 或-SourceFolder。如果你有-SourceFile,你必须有-DestPath等。
其他参数所需的参数链是否可能?如果没有,我至少可以做类似的事情,如果你有-SourceFile,你必须有-DestPath?
【问题讨论】:
-
bugs.python.org/issue11588 探索了添加通用相互依赖测试的方法,但在实现之前,最好的办法是在解析后自己进行测试。
-
这就是 sub-commands 的用途。见
ArgumentParser.add_subparsers()。