Skip to content

Dune init's --public doesn't allow dashes #7108

Closed
ocaml/opam-repository
#24510

Description

@reynir

Expected Behavior

Dune init's --public can take names with dashes in them.

Actual Behavior

An error explaining only characters [a-zA-Z0-9_] are allowed.

Reproduction

$ dune init lib mirage_pair --public mirage-pair
dune: option '--public': invalid component name `mirage-pair'
      Library names must be non-empty and composed only of the
      following
      characters: 'A'..'Z', 'a'..'z', '_' or '0'..'9'.
Usage: dune init library [OPTION]… NAME [PATH]
Try 'dune init library --help' or 'dune --help' for more information.

Specifications

  • Version of dune (output of dune --version): 3.6.1
  • Version of ocaml (output of ocamlc --version) 4.14.0
  • Operating system (distribution and version): debian 11.6

Activity

  1. Alizter commented on Feb 17, 2023

    @Alizter
    Collaborator

    Does putting it in quotations work?

  2. reynir commented on Feb 17, 2023

    @reynir
    ContributorAuthor

    Sorry how do you mean?

  3. Alizter commented on Feb 17, 2023

    @Alizter
    Collaborator

    I mean

    dune init lib mirage_pair --public "mirage-pair"
    
  4. reynir commented on Feb 17, 2023

    @reynir
    ContributorAuthor

    No, that does the same.

  5. reynir commented on Feb 17, 2023

    @reynir
    ContributorAuthor

    The relevant code is here:

    dune/bin/init.ml

    Lines 16 to 48 in d3d628f

    let component_name_parser s =
    (* TODO refactor to use Lib_name.Local.conv *)
    let err_msg () =
    User_error.make
    [ Pp.textf "invalid component 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.Local.of_string_opt s with
    | None -> Error (err_msg ())
    | Some s -> Ok s
    in
    Ok atom
    let atom_conv = Arg.conv (atom_parser, atom_printer)
    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)
    in
    let printer ppf public_name =
    Format.pp_print_string ppf (public_name_to_string public_name)
    in
    Arg.conv (parser, printer)

    The problem is the same converter for library names is used for the public library name. It uses Lib_name.Local

    let valid_char = function
    | 'A' .. 'Z' | 'a' .. 'z' | '_' | '0' .. '9' -> true
    | _ -> false

    I'm unsure if there's existing code that can be used for the public name or how to go forward on this.

  6. added a commit that references this issue on Feb 18, 2023
  7. added a commit that references this issue on Mar 1, 2023
  8. PizieDust commented on Jun 6, 2023

    @PizieDust

    currently having this issue too

  9. added 7 commits that reference this issue on Sep 7, 2023
    78717ba
    19ecc78
    ca33fde
    9f50bee
    d298ae7
    1f2f98f
    cdebdd4
  10. added 2 commits that reference this issue on Sep 11, 2023
    0f555db
    d0b9c61
  11. added a commit that references this issue on Sep 22, 2023
    196c41a
  12. added a commit that references this issue on Jun 18, 2024
    247ff0a
  13. added this to the 3.11.0 milestone on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions