@@ -112,52 +112,66 @@ let filename_of_parts = function
112112 | root :: rest -> List. fold rest ~init: root ~f: Stdlib.Filename. concat
113113
114114let config_file_args =
115+ let suppress_welcome_message () =
116+ Option. value_map ~default: false ~f: Bool. of_string
117+ @@ read_cmdline_or_env_var " suppress_welcome_message"
118+ in
115119 match read_cmdline_or_env_var " no_config_file" with
116- | None | Some "false" -> (
120+ | None | Some "false" ->
117121 let read = Stdio.In_channel. read_lines in
118122 let fname, config_lines =
119123 let rev_dirs = List. rev @@ filename_parts @@ Stdlib.Sys. getcwd () in
120124 let rec find_up = function
121125 | [] ->
122- Stdio. printf
123- " \n Welcome to OCANNL! No ocannl_config file found along current path.\n %!" ;
126+ if not (suppress_welcome_message () ) then
127+ Stdio. printf
128+ " \n Welcome to OCANNL! No ocannl_config file found along current path.\n %!" ;
124129 (" " , [] )
125130 | _ :: tl as rev_dirs -> (
126131 let fname = filename_of_parts (List. rev @@ (" ocannl_config" :: rev_dirs)) in
127132 try (fname, read fname) with Sys_error _ -> find_up tl)
128133 in
129134 find_up rev_dirs
130135 in
131- if String. length fname > 0 then
132- Stdio. printf " \n Welcome to OCANNL! Reading configuration defaults from %s.\n %!" fname;
133- config_lines
134- |> List. filter ~f: (fun l ->
135- not (String. is_prefix ~prefix: " ~~" l || String. is_prefix ~prefix: " #" l))
136- |> List. map ~f: (String. split ~on: '=' )
137- |> List. filter_map ~f: (function
138- | [] -> None
139- | [ s ] when String. is_empty s -> None
140- | key :: [ v ] ->
141- let key =
142- String. (
143- lowercase @@ strip ~drop: (fun c -> equal_char '-' c || equal_char ' ' c) key)
144- in
145- let key =
146- if String. is_prefix key ~prefix: " ocannl" then
147- String. drop_prefix key 6 |> String. strip ~drop: (equal_char '_' )
148- else key
149- in
150- str_nonempty ~f: (pair key) v
151- | l ->
152- failwith @@ " OCANNL: invalid syntax in the config file " ^ fname
153- ^ " , should have a single '=' on each non-empty line, found: " ^ String. concat l)
154- |> Hashtbl. of_alist (module String )
155- |> function
156- | `Ok h -> h
157- | `Duplicate_key key ->
158- failwith @@ " OCANNL: duplicate key in config file " ^ fname ^ " : " ^ key)
136+ let result =
137+ config_lines
138+ |> List. filter ~f: (fun l ->
139+ not (String. is_prefix ~prefix: " ~~" l || String. is_prefix ~prefix: " #" l))
140+ |> List. map ~f: (String. split ~on: '=' )
141+ |> List. filter_map ~f: (function
142+ | [] -> None
143+ | [ s ] when String. is_empty s -> None
144+ | key :: [ v ] ->
145+ let key =
146+ String. (
147+ lowercase @@ strip ~drop: (fun c -> equal_char '-' c || equal_char ' ' c) key)
148+ in
149+ let key =
150+ if String. is_prefix key ~prefix: " ocannl" then
151+ String. drop_prefix key 6 |> String. strip ~drop: (equal_char '_' )
152+ else key
153+ in
154+ str_nonempty ~f: (pair key) v
155+ | l ->
156+ failwith @@ " OCANNL: invalid syntax in the config file " ^ fname
157+ ^ " , should have a single '=' on each non-empty line, found: " ^ String. concat l)
158+ |> Hashtbl. of_alist (module String )
159+ |> function
160+ | `Ok h -> h
161+ | `Duplicate_key key ->
162+ failwith @@ " OCANNL: duplicate key in config file " ^ fname ^ " : " ^ key
163+ in
164+ if
165+ String. length fname > 0
166+ && (not (suppress_welcome_message () ))
167+ && not
168+ (Option. value_map ~default: false ~f: Bool. of_string
169+ @@ Hashtbl. find result " suppress_welcome_message" )
170+ then Stdio. printf " \n Welcome to OCANNL! Reading configuration defaults from %s.\n %!" fname;
171+ result
159172 | Some _ ->
160- Stdio. printf " \n Welcome to OCANNL! Configuration defaults file is disabled.\n %!" ;
173+ if not (suppress_welcome_message () ) then
174+ Stdio. printf " \n Welcome to OCANNL! Configuration defaults file is disabled.\n %!" ;
161175 Hashtbl. create (module String )
162176
163177(* * Retrieves [arg_name] argument from the command line or from an environment variable, returns
0 commit comments