From 0ffb7de6d0086225ec4769fb043a738b23c06810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Fri, 17 Feb 2023 19:51:22 +0100 Subject: [PATCH] dune init lib --public: allow dashes etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Reynir Björnsson --- bin/init.ml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/init.ml b/bin/init.ml index b934941098f..05dae88c9dc 100644 --- a/bin/init.ml +++ b/bin/init.ml @@ -38,9 +38,23 @@ let component_name_conv = Arg.conv (component_name_parser, atom_printer) let public_name_conv = let open Component.Options in - let parser = function - | "" -> Ok Use_name - | s -> component_name_parser s |> Result.map ~f:(fun a -> Public_name a) + let parser s = + let err_msg () = + User_error.make + [ Pp.textf "invalid public library name `%s'" s + ; Lib_name.Local.valid_format_doc + ] + |> User_message.to_string + |> fun m -> `Msg m + in + let open Result.O in + let* atom = atom_parser s in + let* _ = + match Lib_name.of_string_opt s with + | None -> Error (err_msg ()) + | Some s -> Ok s + in + Ok (Public_name atom) in let printer ppf public_name = Format.pp_print_string ppf (public_name_to_string public_name)