Parcourir la source

Allow to set tmp file

Fixes #9
Leo il y a 10 ans
Parent
commit
e2f0bb55b6
7 fichiers modifiés avec 27 ajouts et 16 suppressions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      VERSION
  3. 1 1
      _oasis
  4. 5 4
      setup.ml
  5. 1 0
      src/command_def.ml
  6. 17 9
      src/const.ml
  7. 1 1
      src/oclaunch.ml

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ## 0.2.x
 
 ### v0.2.2
+ + Allow to set tmp file with environment variable “OC\_TMP”. See #9 and #6
  + Add unit tests, to improve stability
  + Clean help
  + Better display after editing an entry. Ignore empty lines and fix #10

+ 1 - 1
VERSION

@@ -1 +1 @@
-
+0.2.2-dev

+ 1 - 1
_oasis

@@ -1,6 +1,6 @@
 OASISFormat: 0.4
 Name:        OcLaunch
-Version:     
+Version:     0.2.2-dev
 Synopsis:    Launch commands automagically
 Authors:     Joly Clément <leowzukw@vmail.me>
 Maintainers: Joly Clément <leowzukw@vmail.me>

+ 5 - 4
setup.ml

@@ -1,7 +1,7 @@
 (* setup.ml generated for the first time by OASIS v0.4.5 *)
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: e85537f969feafc7b8eee94a9fce28c0) *)
+(* DO NOT EDIT (digest: facda6205b6c2f62ccec277c5a0df974) *)
 (*
    Regenerated by OASIS v0.4.5
    Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6851,7 +6851,7 @@ let setup_t =
           alpha_features = ["stdfiles_markdown"; "compiled_setup_ml"];
           beta_features = [];
           name = "OcLaunch";
-          version = "";
+          version = "0.2.2-dev";
           license =
             OASISLicense.DEP5License
               (OASISLicense.DEP5Unit
@@ -7019,7 +7019,8 @@ let setup_t =
        };
      oasis_fn = Some "_oasis";
      oasis_version = "0.4.5";
-     oasis_digest = Some "\203\134\148\142Uh\206\188\027iR\241>##\179";
+     oasis_digest =
+       Some "w\231\183\238E\027\192\029\180\212\172\209\001\200h\003";
      oasis_exec = None;
      oasis_setup_args = [];
      setup_update = false
@@ -7027,6 +7028,6 @@ let setup_t =
 
 let setup () = BaseSetup.setup setup_t;;
 
-# 7031 "setup.ml"
+# 7032 "setup.ml"
 (* OASIS_STOP *)
 let () = setup ();;

+ 1 - 0
src/command_def.ml

@@ -102,6 +102,7 @@ let commands =
        (* Use given rc file, should run the nth argument if present *)
        Const.rc_file := (Lazy.return rc_file_name);
        Messages.debug (sprintf "Configuration file is %s" (Lazy.force !Const.rc_file));
+       Messages.debug (sprintf "Tmp file is %s" Const.tmp_file);
        (* Obtain data from rc_file *)
        let rc_content = File_com.init_rc () in
        (* A default number, corresponding to first item *)

+ 17 - 9
src/const.ml

@@ -40,16 +40,24 @@ open Core.Std;;
 
 (* General function to get environment variables
  * exp: exception*)
-let get_var ?(exp=false) name =
+let get_var ?(exp=false) ?default name =
     let msg =
         lazy (sprintf "ERROR: Couldn't get %s. Please consider setting it." name)
     in
-    match exp with
-    | true -> Sys.getenv name |>
-        (function
-            Some x -> x
-            | None -> failwith (Lazy.force msg))
-    | false -> print_endline (Lazy.force msg); ""
+    (* Return value or exception *)
+    let run_exn () =
+        match exp with
+        | true -> failwith (Lazy.force msg)
+        | false -> print_endline (Lazy.force msg); ""
+    in
+    (* Get the var *)
+    Sys.getenv name
+    |> (function
+        | Some x -> x
+        | None ->
+                match default with
+                | None -> run_exn ()
+                | Some default -> default)
 ;;
 
 (* Get current home *)
@@ -58,7 +66,7 @@ let home =
 ;;
 
 (* Get default editor *)
-let editor = (* If editor is not set, it gets "", but an exeption is trowed *)
+let editor = (* If editor is not set, it gets "", but an exception is raised *)
     lazy (get_var ~exp:true "EDITOR")
 ;;
 
@@ -73,4 +81,4 @@ let rc_file_default = Lazy.(home >>| (fun home -> home ^ "/" ^
 (* Current place to read settings, maybe modified from command line argument *)
 let rc_file = ref rc_file_default;;
 (* Set tmp file, in witch stock launches, in biniou format *)
-let tmp_file = "/tmp/.oclaunch_trace.dat";; (* File where launch are logged *)
+let tmp_file = get_var ~default:"/tmp/.oclaunch_trace.dat" "OC_TMP";; (* File where launch are logged *)

+ 1 - 1
src/oclaunch.ml

@@ -38,7 +38,7 @@ open Core.Std;;
 
 (* Variable to store version number *)
 (* TODO Get value from file *)
-let version_number = "";;
+let version_number = "0.2.2-dev";;
 
 (* Variable store building information *)
 (* XXX This is fake value, it corresponds to the running