Browse Source

Improve spying expression

Leo 8 years ago
parent
commit
6d1588cc08
3 changed files with 15 additions and 1 deletions
  1. 1 1
      src/tmp_file.ml
  2. 12 0
      src/tools.ml
  3. 2 0
      src/tools.mli

+ 1 - 1
src/tmp_file.ml

@@ -250,7 +250,7 @@ let reset_all () =
   Messages.debug "Asking question";
   Messages.confirm "You will lose number of launch for every command. \
                     Are you sure?"
-  |> (fun answer -> sprintf "Answer %s" (Messages.answer2str answer) |> Messages.debug; answer) (* Spy *)
+  |> Tools.spy1_answer
   |> function
     Messages.Yes -> reset_without_ask (); Messages.ok "Successfully reseted!"
   | Messages.No -> ()

+ 12 - 0
src/tools.ml

@@ -63,6 +63,12 @@ let spy1_int_option io =
 let spy1_string str =
   spy str str
 ;;
+let spy1_string_option so =
+  so
+  |> (function None -> "None"
+      | Some str -> sprintf "Some %s" str)
+  |> spy so
+;;
 let spy1_float f =
   sprintf "%f" f
   |> spy f
@@ -83,6 +89,12 @@ let spy1_log (log : (string * int) list) =
   |> printing;
   log
 ;;
+let spy1_answer answer =
+  answer
+  |> Messages.answer2str
+  |> sprintf "Answer %s"
+  |> spy answer
+;;
 
 (* It's simpler to define strings (for instance in the test) and convert it to
  * entry then *)

+ 2 - 0
src/tools.mli

@@ -40,7 +40,9 @@ open Core.Std;;
 val spy1_int : int -> int
 val spy1_int_option : int option -> int option
 val spy1_string : string -> string
+val spy1_string_option : string option -> string option
 val spy1_float : float -> float
 val spy1_list : f:('a -> string)-> 'a list -> 'a list
 val spy1_log : (string * int) list -> (string * int) list
+val spy1_answer : Messages.answer -> Messages.answer
 val to_entry : string -> Rc.entry