[ANN] ez_subst.0.1.0 and ez_cmdliner.0.2.0

Hi,

I am please to announce the new releases of two opam packages: ez_subst and ez_cmdliner. We use both of them as dependencies of drom (and use drom to manage them).

  • ez_subst is a simple library to perform string replacements in strings. It can be seen as a replacement for Printf when you are lost with too many %s in one format, or a replacement for Buffer.add_substitute when you want a more control. Replacements are chosen by functions, and can be separately specified using optional arguments ~brace (for ${var}), ~paren (for $(var)), ~bracket (for $[var]) and ~var (for $alphanum). Separator $ can be changed, and notation can be symmetric (%{x}%).

    https://ocamlpro.github.io/ez_subst
    https://ocamlpro.github.io/ez_subst/doc/ez_subst/Ez_subst/V1/EZ_SUBST/index.html

    For example:

    open Ez_subst.V1 (* versionned interface *)
    
    let s = EZ_SUBST.string ~brace:(fun ctxt n -> string_of_int
      (ctxt + int_of_string n)) ~ctxt:3 "${4} ${5}"
    
    let s = EZ_SUBST.string ~sep:'!'  ~paren:(fun () s ->
      String.uppercase s) ~ctxt:() "!(abc) !(def)"
    
    let s = EZ_SUBST.string ~sym:true ~sep:'%' ~brace:(fun ctxt_ s
      -> ctxt ^ " " ^ s) ~ctxt:"Hello" "%{John}% %{Sandy}%"
    
    let s = EZ_SUBST.string_from_list ~default:"unknown" [ "name",
      "Doe"; "surname", "John" ] "${name} $(surname) is missing"
    
  • ez_cmdliner is a simple layer over cmdliner to provide an interface à la Arg module. It provides support for a one-command and sub-commands modes. It also provides a ReST generator to document sub-commands and integrate the documentation in a Sphinx documentation (to use with drom for example).

    https://ocamlpro.github.io/ez_cmdliner

    For example:

   open Ezcmd.V2
   let cmd_new =  EZCMD.sub "new"   (* for `drom new` *)
    ~args: [
     [ "dir" ],  Arg.String (fun s -> dir := Some s),
        EZCMD.info ~docv:"DIRECTORY"
         "Dir where package sources are stored (src by default)";
     [ "library" ],  Arg.Unit (fun () -> skeleton := Some "library"),
        EZCMD.info "Project contains only a library";
     [ "i"; "inplace" ], Arg.Set inplace, (* for `-i` or `--inplace` *)
         EZCMD.info "Create project in the the current directory";
     [],    Arg.Anon (0, fun name -> project_name := Some name),
         EZCMD.info ~docv:"PROJECT" "Name of the project" 
    ]
    ~doc:"Create a new project"
    (fun () ->
       action ~name:!project_name ~skeleton:!skeleton ~dir:!dir
         ~inplace:!inplace ~args)
    ~man: [
      `S "DESCRIPTION";
      `Blocks [
        `P "This command performs the following actions:";
      ]
   ]
   let () = EZCMD.main_with_subcommands ~name:"drom" ~version:"0.1.0"
      ~doc:"Create and manage an OCaml project" ~man:[] ~argv [ cmd_new ]
      ~common_args

Both packages are now available in opam repository.


Fabrice

3 Likes