bn-d / ppx_subliner

[@@ deriving] plugin to generate Cmdliner sub-command groups, and ppx rewriter to generate Cmdliner evaluations.
https://boni.ng/ppx_subliner/ppx_subliner/index.html
MIT License
15 stars 0 forks source link

Can't mix subliner with other deriving in script #33

Open aryx opened 4 months ago

aryx commented 4 months ago

Great library, but I didn't manage to mix the use of subliner with other deriving libraries.

For example this script:

#!/usr/bin/env ocaml

#use "topfind"
#require "ppx_subliner"
#require "ppx_deriving.show"

type conf = {
    username : string; [@default "pad"]
    debug : bool; [@defaul false]
    command : string; [@pos 0] [@doc "CMD"]
}
[@@deriving subliner, show]

let run (conf : conf) =
  Printf.printf "Hello %s\n" conf.command

let () =
   let info = Cmdliner.Cmd.info Sys.argv.(0) in
   let term = Cmdliner.Term.(const run $ conf_cmdliner_term ()) in
   let cmd = Cmdliner.Cmd.v info term in
   exit (Cmdliner.Cmd.eval cmd)

fails to run with

File "/tmp/test.ml", line 12, characters 12-20:
12 | [@@deriving subliner, show]
                 ^^^^^^^^
Error: Cannot locate deriver subliner

If I remove the use of ppx_deriving.show then it works fine. Looks like we can't have both at the same time. This was working though with ppx_deriving.cmdliner

aryx commented 4 months ago

for reference: https://github.com/semgrep/semgrep/pull/9926

bn-d commented 4 months ago

The test script also failed for me. But with slightly different error:

$ ./repl
File "./repl", line 12, characters 13-27:
12 | [@@deriving  subliner, show]
                  ^^^^^^^^^^^^^^
Error: Ppxlib.Deriving: 'subliner' is not a supported type deriving generator

I was not able to get any two derivers working together in REPL. The same lines of code built fine in dune. So I would suspect it is a problem of REPL.

I actually use subliner with show (ppx_show instead of ppx_deriiving.show) in the test. It compiled and ran with no error.

https://github.com/bn-d/ppx_subliner/blob/6ebdf8596ba32aa9410574db70eb3652f020a4f3/test/cmdliner/test_ppx_deriving_cmdliner.ml#L76-L84