Parcourir la source

Allow to set some command line parameters with environment variable

 + Prepared in commit d49901c7ba71131ac7774375179459414cd942d3
 + Progress with #20
 + Doesn't work properly for color, since its erased in command definition
 (command_def.ml).
Leo il y a 9 ans
Parent
commit
689588fc13
1 fichiers modifiés avec 19 ajouts et 5 suppressions
  1. 19 5
      src/const.ml

+ 19 - 5
src/const.ml

@@ -69,13 +69,27 @@ let editor = (* If editor is not set, it gets "", but an exception is raised *)
 ;;
 
 (* Level of verbosity, used by Messages module *)
-let verbosity = ref 4;;
-(* Use do not use colors *)
-let no_color = ref false;;
+let verbosity =
+  ref (get_var ~default:(lazy "4") (lazy "OC_VERB")
+       |> Lazy.force
+       |> Int.of_string);;
+(* Use do not use colors, 0 -> false, anything -> true *)
+let no_color =
+  ref (get_var ~default:(lazy "0") (lazy "OC_COLOR")
+       |> Lazy.force
+       |> (function "0" -> false | _ -> true)
+       )
+;;
 
 (* Default place to read settings *)
-let rc_file_default = Lazy.(home >>| (fun home -> home ^ "/" ^
-                                                  ".oclaunch_rc.json"));;
+let rc_file_default =
+  let internal_default : string lazy_t =
+    (* Default value, if no value is given (for instance as
+    command line argument), or no environnement variable is set *)
+    Lazy.(home >>| fun home -> home ^ "/" ^ ".oclaunch_rc.json")
+  in
+  get_var ~default:internal_default (lazy "OC_RC")
+;;
 (* 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 *)