mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 16:28:12 +03:00
feat(utils): add File.ocamlformat_file_opt
This commit is contained in:
parent
7ad81158eb
commit
677ff92ae6
@ -338,7 +338,8 @@ let driver source_file (options : Cli.options) : int =
|
||||
Cli.debug_print "Compiling program into OCaml...";
|
||||
Cli.debug_print "Writing to %s..."
|
||||
(Option.value ~default:"stdout" output_file);
|
||||
Lcalc.To_ocaml.format_program fmt prgm type_ordering
|
||||
Lcalc.To_ocaml.format_program fmt prgm type_ordering;
|
||||
File.ocamlformat_file_opt output_file
|
||||
| `Plugin (Plugin.Lcalc p) ->
|
||||
let output_file, _ = get_output ~ext:p.Plugin.extension () in
|
||||
Cli.debug_print "Compiling program through backend \"%s\"..."
|
||||
|
@ -45,3 +45,10 @@ let with_formatter_of_opt_file filename_opt f =
|
||||
match filename_opt with
|
||||
| None -> finally (fun () -> flush stdout) (fun () -> f Format.std_formatter)
|
||||
| Some filename -> with_formatter_of_file filename f
|
||||
|
||||
let ocamlformat_file_opt = function
|
||||
| Some f ->
|
||||
Cli.debug_print "Formatting %s..." f;
|
||||
if Sys.command (Printf.sprintf "ocamlformat %s -i" f) <> 0 then
|
||||
failwith ("Internal error: ocamlformat failed on " ^ f)
|
||||
| None -> ()
|
||||
|
@ -40,3 +40,7 @@ val with_formatter_of_opt_file : string option -> (Format.formatter -> 'a) -> 'a
|
||||
(** [with_formatter_of_opt_file filename_opt f] manages the formatter created
|
||||
from the file [filename_opt] if there is some (see
|
||||
{!with_formatter_of_file}), otherwise, uses the [Format.std_formatter]. *)
|
||||
|
||||
(** {2 Utility functions on files} *)
|
||||
|
||||
val ocamlformat_file_opt : string option -> unit
|
||||
|
Loading…
Reference in New Issue
Block a user