From 33d738e45c21254ce5ba5e7bf7604626d93685c5 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Thu, 14 Nov 2019 14:38:19 +0100 Subject: [PATCH] Remove load-time argv parsing `Conf.action` had side effects as it immediately parsed `Sys.argv` at load time. This has to be delayed so that we can link the lib in a test suite for example. --- CHANGES.md | 2 +- bin/ocamlformat.ml | 2 +- bin/ocamlformat_reason.ml | 2 +- lib/Conf.ml | 2 +- lib/Conf.mli | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 87b58fb636..a5deb92020 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,7 +18,7 @@ + Testing interactions between break-infix and break-infix-before-func (#1136) (Guillaume Petiot) + Add dune to repositories checked for regressions (#1129) (Jules Aguillon) + Use an expect test for cli tests (#1126) (Etienne Millon) - + Factor out a private library (#1134) (Etienne Millon) + + Factor out a private library (#1134, #1148) (Etienne Millon) + Remove global reference `Cmts.remove` (#1142) (Etienne Millon) #### Documentation diff --git a/bin/ocamlformat.ml b/bin/ocamlformat.ml index f3c15f493d..330bc0815b 100644 --- a/bin/ocamlformat.ml +++ b/bin/ocamlformat.ml @@ -68,7 +68,7 @@ let source_from_file = function | File f -> In_channel.with_file f ~f:In_channel.input_all ;; -match Conf.action with +match Conf.action () with | Inplace inputs -> let errors = List.filter_map inputs diff --git a/bin/ocamlformat_reason.ml b/bin/ocamlformat_reason.ml index 6bbda7c589..5c87e9e4c3 100644 --- a/bin/ocamlformat_reason.ml +++ b/bin/ocamlformat_reason.ml @@ -57,7 +57,7 @@ let to_output_file output_file data = | Some output_file -> Out_channel.write_all output_file ~data ;; -match Conf.action with +match Conf.action () with | Inplace _ -> user_error "Cannot convert Reason code with --inplace" [] | Check _ -> user_error "Cannot check Reason code with --check" [] | In_out ({kind; file; name= input_name; conf}, output_file) -> ( diff --git a/lib/Conf.ml b/lib/Conf.ml index eee3fb4bda..ffd0828f1e 100644 --- a/lib/Conf.ml +++ b/lib/Conf.ml @@ -2172,7 +2172,7 @@ let validate () = | Error e -> `Error (false, e) | Ok action -> `Ok action -let action = parse info validate +let action () = parse info validate let debug = !debug diff --git a/lib/Conf.mli b/lib/Conf.mli index d62e3ff544..0278d3c854 100644 --- a/lib/Conf.mli +++ b/lib/Conf.mli @@ -100,7 +100,7 @@ type action = (** Check whether the input files already are formatted. *) | Print_config of t (** Print the configuration and exit. *) -val action : action +val action : unit -> action (** Formatting action: input type and source, and output destination. *) val debug : bool