Browse Source

Code clean up

Place messages to avoid incorrect display because of misused functions. They can
now be used with less problem.
Leo 9 years ago
parent
commit
1b9cc33216
3 changed files with 10 additions and 12 deletions
  1. 1 0
      CHANGELOG.md
  2. 6 2
      src/default.ml
  3. 3 10
      src/exec_cmd.ml

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@
 
  + Fix bug: in special circumstances, it was not possible to write in lock file.
    The program was crashing.
+ + Code clean up
  + Changed tmp file format, the new one would allow to do more things:
    + Restart edited command (reset number of launch)
    + Support multiple configuration file

+ 6 - 2
src/default.ml

@@ -49,8 +49,12 @@ let run ~rc cmd_number =
   match cmd_number with
     | None -> begin
         (* Execute each item (one by one) in config file *)
-        let cmd_to_exec = Exec_cmd.what_next ~tmp in
-        Exec_cmd.execute cmd_to_exec;
+        Exec_cmd.what_next ~tmp
+          |> function
+            | None -> (* If no command was found, all has been launched *)
+                Messages.ok "All has been launched!";
+                Messages.tips "You can reset with '-r'";
+            | Some cmd_to_exec -> Exec_cmd.execute cmd_to_exec;
       end
     | Some num -> begin
         File_com.num_cmd2cmd ~rc num

+ 3 - 10
src/exec_cmd.ml

@@ -61,20 +61,11 @@ let less_launched (log : (string * int) list) =
 ;;
 
 (* Function to determinate what is the next command to
- * execute. It takes the current number from tmp file. *)
+ * execute. It takes the current numbers from tmp file. *)
 let what_next ~tmp =
   Tmp_file.get_accurate_log ~tmp ()
   (* Find the less launched, with order *)
   |> less_launched
-  |> function
-    (* If in range of the list, return the corresponding command else return
-     * an empty string after displaying error. *)
-    | Some x -> set_title x; x
-    | None ->
-        Messages.ok "All has been launched!";
-        Messages.tips "You can reset with '-r'";
-        (* Return empty string *)
-        ""
 ;;
 
 (* Display an error message if command can't run
@@ -91,6 +82,8 @@ let display_result command status =
 
 (* Execute some command and log it *)
 let execute ?(display=true) cmd =
+  set_title cmd;
+
     Tmp_file.log ~cmd ~func:((+) 1) ();
     if display then
         Messages.ok cmd;