Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions lib/bin_conf/Bin_conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,6 @@ let update_using_env conf =
| [] -> conf
| l -> failwith_user_errors ~from:"OCAMLFORMAT environment variable" l

let discard_formatter =
Format.(
formatter_of_out_functions
{ (get_formatter_out_functions ()) with
out_string= (fun _ _ _ -> ())
; out_flush= (fun () -> ()) } )

let global_lib_term =
Term.(
const (fun conf_modif lib_conf ->
Expand All @@ -537,8 +530,9 @@ let global_lib_term =

let global_lib_term_eval =
lazy
(Cmd.eval_value ~err:discard_formatter ~help:discard_formatter
(Cmd.v info global_lib_term) )
(let discard = Format.formatter_of_buffer (Buffer.create 0) in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we no longer have to maintain the formatter_out_functions definition that seems unstable.
Do you think we could use Format.make_formatter to also avoid writing to a buffer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I looked for a function like this, but didn't see it.

We could use it, but I slightly prefer the buffer as it's just obviously correct (with the other version, you need to consult the documentation). And the formatter and the buffer are going to get gc'ed shortly after the lazy is forced (unless cmdliner is doing weird things).

I think what would make more sense is to stop suppressing errors, and move the command line parsing upfront, but maybe there's a reason why things are the way they are.

Cmd.eval_value ~err:discard ~help:discard (Cmd.v info global_lib_term)
)

let update_using_cmdline config =
match Lazy.force global_lib_term_eval with
Expand Down
Loading