我想用OCaml中的参数解析命令行选项。OCaml - 使用参数解析带参数的命令行选项
标准库的模块Arg
似乎做我需要的一切,并有一些教程解释如何使用此模块。
我的问题是,当一个选项的参数丢失时,它们似乎都共享相同的奇怪行为。例如,从与this example./a.out -d
执行程序产生以下输出:
./a.out: option '-d' needs an argument.
usage: ./a.out [-b] [-s string] [-d int]
-b : set somebool to true
-s : what follows -s sets some string
-d : some int parameter
-help Display this list of options
--help Display this list of options
./a.out: ./a.out: option '-d' needs an argument.
usage: ./a.out [-b] [-s string] [-d int]
-b : set somebool to true
-s : what follows -s sets some string
-d : some int parameter
-help Display this list of options
--help Display this list of options
.
usage: ./a.out [-b] [-s string] [-d int]
-b : set somebool to true
-s : what follows -s sets some string
-d : some int parameter
-help Display this list of options
--help Display this list of options
我无法找出为什么错误/用法消息被打印三次。这也发生在我在网上找到的所有其他代码示例中。这是Arg
模块中的问题,还是在这些示例中以某种方式未正确使用?
你使用什么版本的编译器? (我已经设法在4.04.2下现在重现) – RichouHunter
使用OCaml 4.02.3运行不会导致此行为。我建议你检查一下[OCaml bug-tracker](https://caml.inria.fr/mantis/view_all_bug_page.php),看看这个问题是否曾经被报告过。 :) – RichouHunter