1

这行有问题,这就是我想要的: - 我输入(在执行时)-g 0,我与 g 关联的功能被禁用 - 我输入 -g 1(或任何数字)我的功能被启用

我想输入的示例:

./main.ml -g 1

我的代码部分:

let greytf = ref 0 in

(...)

 let parse_command =
[("-g", if Arg.Int () <> 0 then (( greytf := 1)) else (greytf := 0) , "Enable I\
mage To Grey Mode");]

提前致谢

4

1 回答 1

1

布尔引用更适合“标志”选项:

let _ =
    let a_flag = ref false in
    let b_flag = ref false in
    let opt = [
        ("-a", Arg.Set a_flag,
            " This is a a flag");
        ("-b", Arg.Set b_flag,
            " This is a b flag")
    ] in
    Arg.parse
        (Arg.align opt)
        (fun a -> raise (Arg.Bad ("Bad argument: " ^ a)))
        "Usage: usage message";
    (* flag tests *)
    Printf.printf "A flag: %b\n" !a_flag;
    Printf.printf "B flag: %b\n" !b_flag
于 2013-10-20T21:02:58.880 回答