Skip to content

Commit

Permalink
Remove load-time argv parsing
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
emillon committed Nov 14, 2019
1 parent 2e62859 commit 66135e1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/ocamlformat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/ocamlformat_reason.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> (
Expand Down
2 changes: 1 addition & 1 deletion lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Conf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 66135e1

Please sign in to comment.