Browse Source

Add command flag

 - Allow to reinitialise tmp file from command line
Leo 10 years ago
parent
commit
836927543b
4 changed files with 14 additions and 4 deletions
  1. 0 1
      TODO.md
  2. 1 1
      src/default.ml
  3. 8 2
      src/oclaunch.ml
  4. 5 0
      src/tmp_file.ml

+ 0 - 1
TODO.md

@@ -7,7 +7,6 @@
 
 
 ### Commands
 ### Commands
  + Add command to modify configuration file
  + Add command to modify configuration file
- + Allow to reinitialise tmp file from command line
 
 
 ### Configuration value
 ### Configuration value
  + Make displaying command before launching configurable
  + Make displaying command before launching configurable

+ 1 - 1
src/default.ml

@@ -39,7 +39,7 @@ open Core.Std;;
 (* The module containing the step runned when the program is
 (* The module containing the step runned when the program is
  * used without argument *)
  * used without argument *)
 
 
-let run ~rc:rc_content ~tmp:tmp_content cmd_number () =
+let run ~rc:rc_content ~tmp:tmp_content cmd_number =
   (* cmd_number is the number of the command the user wants
   (* cmd_number is the number of the command the user wants
    * to execute *)
    * to execute *)
   match cmd_number with
   match cmd_number with

+ 8 - 2
src/oclaunch.ml

@@ -58,8 +58,14 @@ let commands =
     ~summary:"OcLaunch program is published under CeCILL licence. See https://gitlab.com/WzukW/oclaunch for details"
     ~summary:"OcLaunch program is published under CeCILL licence. See https://gitlab.com/WzukW/oclaunch for details"
     ~readme:(fun () -> "See https://gitlab.com/WzukW/oclaunch for help")
     ~readme:(fun () -> "See https://gitlab.com/WzukW/oclaunch for help")
     (* TODO if number is out of the mist, return error message *)
     (* TODO if number is out of the mist, return error message *)
-    Command.Spec.(empty +> anon (maybe ("Command number" %: int)))
-    (Default.run ~rc:rc_content ~tmp:tmp_content)
+    Command.Spec.(empty
+    +> flag "--reset-tmp" no_arg ~doc:"Reinitialises launches by deleting temporal file."
+    +> anon (maybe ("Command number" %: int)))
+    (fun reset_tmp num_cmd () ->
+       match reset_tmp with
+         | true -> Tmp_file.reset ~tmp:tmp_content
+         | false -> Default.run ~rc:rc_content ~tmp:tmp_content num_cmd
+    )
 ;;
 ;;
 
 
 let () =
 let () =

+ 5 - 0
src/tmp_file.ml

@@ -70,3 +70,8 @@ let rec is_prog_in_rc list_from_rc_file program = (* TODO restaure ?(list_from_r
     | [] -> false
     | [] -> false
     | hd :: tl -> if hd = program then true else is_prog_in_rc tl program
     | hd :: tl -> if hd = program then true else is_prog_in_rc tl program
 ;;
 ;;
+
+(* Delete tmp file, to reinitialise program *)
+let reset ~tmp =
+  Sys.remove tmp
+;;