|
@@ -60,6 +60,7 @@ type color =
|
|
| Yellow
|
|
| Yellow
|
|
| White
|
|
| White
|
|
| Plum
|
|
| Plum
|
|
|
|
+ | Cyan
|
|
;;
|
|
;;
|
|
|
|
|
|
type style =
|
|
type style =
|
|
@@ -84,6 +85,7 @@ let print ~color ~style message =
|
|
| Yellow -> Color_print.color ~color:`Yellow message
|
|
| Yellow -> Color_print.color ~color:`Yellow message
|
|
| White -> Color_print.color ~color:`White message
|
|
| White -> Color_print.color ~color:`White message
|
|
| Plum -> Color_print.color ~color:`Plum message
|
|
| Plum -> Color_print.color ~color:`Plum message
|
|
|
|
+ | Cyan -> Color_print.color ~color:`Cyan message
|
|
) |> (* Finaly print escaped string *)
|
|
) |> (* Finaly print escaped string *)
|
|
(fun colored_msg ->
|
|
(fun colored_msg ->
|
|
match style with
|
|
match style with
|
|
@@ -104,6 +106,7 @@ let check_verbosity ~f function_number =
|
|
| false -> ()
|
|
| false -> ()
|
|
;;
|
|
;;
|
|
|
|
|
|
|
|
+
|
|
(* Print debugging, information, important... messages *)
|
|
(* Print debugging, information, important... messages *)
|
|
let debug message =
|
|
let debug message =
|
|
check_verbosity ~f:(fun () ->
|
|
check_verbosity ~f:(fun () ->
|
|
@@ -126,6 +129,38 @@ let warning message =
|
|
) 1
|
|
) 1
|
|
;;
|
|
;;
|
|
|
|
|
|
|
|
+(* Type for the answers *)
|
|
|
|
+type answer = Yes | No;;
|
|
|
|
+(* State of the program, if you should always answer yes, no or ask to the user
|
|
|
|
+ * (default)*)
|
|
|
|
+(* TODO Put it in Const *)
|
|
|
|
+let assume_yes = None;;
|
|
|
|
+(* Allow to assume yes or no like with a --yes option *)
|
|
|
|
+let check_assume_yes ~f =
|
|
|
|
+ match assume_yes with
|
|
|
|
+ | Some true -> Yes (* --yes *)
|
|
|
|
+ | Some false -> No (* --no *)
|
|
|
|
+ | None -> f ()
|
|
|
|
+;;
|
|
|
|
+
|
|
|
|
+(* Get confirmation
|
|
|
|
+ * TODO:
|
|
|
|
+ * allow option like -y
|
|
|
|
+ * test it *)
|
|
|
|
+let rec confirm info =
|
|
|
|
+ check_assume_yes ~f:(fun () ->
|
|
|
|
+ print ~color:Cyan ~style:Normal info;
|
|
|
|
+ print ~color:Cyan ~style:Normal "Are you sure ? (Yes/No): ";
|
|
|
|
+ In_channel.(input_line ~fix_win_eol:true stdin)
|
|
|
|
+ |> (function
|
|
|
|
+ | Some "Y" | Some "y" | Some "Yes" | Some "YES" | Some "yes" -> Yes
|
|
|
|
+ | Some "N" | Some "n" | Some "No" | Some "NO" | Some "no" -> No
|
|
|
|
+ | Some _ | None ->
|
|
|
|
+ warning "Please enter 'yes' or 'no' or 'y' or 'n'.";
|
|
|
|
+ confirm info)
|
|
|
|
+ )
|
|
|
|
+;;
|
|
|
|
+
|
|
let ok message =
|
|
let ok message =
|
|
check_verbosity ~f:(fun () ->
|
|
check_verbosity ~f:(fun () ->
|
|
let mess = message ^ "\n" in
|
|
let mess = message ^ "\n" in
|