Browse Source

Improve resetting: tips, way to roll back

Leo 10 years ago
parent
commit
4230f26862
5 changed files with 18 additions and 10 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      src/list_rc.ml
  3. 1 9
      src/state.ml
  4. 13 0
      src/tmp_file.ml
  5. 2 0
      src/tmp_file.mli

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ## 0.2.x
 
 ### v0.2.2
+ + Improve resetting: tips, way to roll back
  + Allow to set tmp file with environment variable “OC\_TMP”. See #9 and #6
  + Add unit tests, to improve stability
  + Allow to install from opam throw opam pin add <pkg> <repo>

+ 1 - 1
src/list_rc.ml

@@ -53,5 +53,5 @@ let disp_cmd_num current_number number command =
 (* Function which list *)
 let run ~(rc:File_com.t) =
     List.iteri rc.Settings_t.progs ~f:(fun i item ->
-        disp_cmd_num (State.get_current ()) i item)
+        disp_cmd_num (Tmp_file.get_current ()) i item)
 ;;

+ 1 - 9
src/state.ml

@@ -38,17 +38,9 @@ open Core.Std;;
 
 (* Module to display the current state of the program *)
 
-(* Return current number *)
-let get_current () =
-    (* Read tmp file *)
-    let tmp_file = Tmp_file.init () in
-    (* Return the number *)
-    tmp_file.Tmp_biniou_t.number;
-;;
-
 (* Display current number *)
 let print_current () =
     (* Display the number *)
-    sprintf "Current state: %i" (get_current ())
+    sprintf "Current state: %i" (Tmp_file.get_current ())
     |> Messages.ok
 ;;

+ 13 - 0
src/tmp_file.ml

@@ -113,11 +113,24 @@ let log ?(func= (+) 1 ) () =
   write { file with Tmp_biniou_t.number = (func file.Tmp_biniou_t.number)}
 ;;
 
+(* Return current number *)
+let get_current () =
+    (* Read tmp file *)
+    let tmp_file = init () in
+    (* Return the number *)
+    tmp_file.Tmp_biniou_t.number;
+;;
+
 (* Reset command number in two ways :
     * if cmd_num is 0, delete tmp file, to reinitialise program
     * if cmd_num is 0>, set to this value
     * else display an error message *)
 let reset cmd_num =
+    let n = get_current () in
+    sprintf  "Last N was %i" n
+    |> Messages.info;
+    sprintf  "Restore with 'oclaunch -r %i'" n
+    |> Messages.tips;
     match cmd_num with
     | 0 -> (*Verify that file exist and if not, delete it *)
             Sys.file_exists Const.tmp_file

+ 2 - 0
src/tmp_file.mli

@@ -43,4 +43,6 @@ val init : unit -> t
 val verify_key_exist : key:'a -> 'a -> bool
 val is_prog_in_rc : 'a list -> 'a -> bool
 val log : ?func:(int -> int) -> unit -> unit
+(** Return current state *)
+val get_current : unit -> int
 val reset : int -> unit