Got a problem with this line, here's what I want: - I enter (while executing) -g 0, my function associated to g is disabled - I enter -g 1 (or any number) my function is enabled
Exemple of what I'd like to enter:
./main.ml -g 1
My part of Code:
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");]
Thanks in advance
Boolean references are better suited for "flag" options:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.