Parcourir la source

Restore state subcommand, not working properly

 + Says when nothing more to launch
 + Doesn't give the next command to launch each time
Leo il y a 9 ans
Parent
commit
cc69a229ce
3 fichiers modifiés avec 28 ajouts et 7 suppressions
  1. 2 2
      src/command_def.ml
  2. 11 1
      src/exec_cmd.ml
  3. 15 4
      src/state.ml

+ 2 - 2
src/command_def.ml

@@ -173,8 +173,8 @@ let state =
       empty
       empty
       +> shared_params
       +> shared_params
     )
     )
-    (fun _ () ->
-      State.print_current ())
+    (fun { rc } () ->
+      State.print_current ~rc ())
 ;;
 ;;
 
 
 
 

+ 11 - 1
src/exec_cmd.ml

@@ -46,7 +46,7 @@ let set_title new_title =
 ;;
 ;;
 
 
 (* Function to return the less launched command, at least the first one *)
 (* Function to return the less launched command, at least the first one *)
-(* Log is a list of entry (commands) asociated with numbers *)
+(* Log is a list of entry (commands) associated with numbers *)
 let less_launched (log : (string * int) list) =
 let less_launched (log : (string * int) list) =
   let max = Const.default_launch in (* Number of launch, maximum *)
   let max = Const.default_launch in (* Number of launch, maximum *)
   (* Return smallest, n is the smaller key *)
   (* Return smallest, n is the smaller key *)
@@ -59,6 +59,16 @@ let less_launched (log : (string * int) list) =
       | None -> None)
       | None -> None)
 ;;
 ;;
 
 
+(* Function to get the number corresponding to the next command to launch (less
+ * launched) *)
+(* TODO Test it *)
+let less_launched_num log =
+  less_launched log
+    |> function
+      | Some cmd -> List.Assoc.find log cmd
+      | None -> None
+;;
+
 (* Function to determinate what is the next command to
 (* Function to determinate what is the next command to
  * execute. It takes the current numbers from tmp file. *)
  * execute. It takes the current numbers from tmp file. *)
 let what_next ~tmp =
 let what_next ~tmp =

+ 15 - 4
src/state.ml

@@ -39,8 +39,19 @@ open Core.Std;;
 (* Module to display the current state of the program *)
 (* Module to display the current state of the program *)
 
 
 (* Display current number *)
 (* Display current number *)
-let print_current () =
-    (* Display the number *)
-    sprintf "Current state: %i" (Tmp_file.get_current ())
-    |> Messages.ok
+let print_current ~rc () =
+  (* Display the number *)
+  Tmp_file.(init ()
+    |> (fun tmp -> get_accurate_log ~tmp ())
+    |> Exec_cmd.less_launched_num)
+  |> Option.value_map
+    ~default:"Nothing next"
+    ~f:(fun num ->
+      File_com.num_cmd2cmd ~rc num
+      |> (function
+        | Some cmd -> cmd
+        | None -> Messages.warning "Error, should not append, this is a bug";
+        assert false)
+      |> (fun ( cmd : string ) -> sprintf "Next: command %i, '%s'" num cmd))
+  |> Messages.ok
 ;;
 ;;