Giter Site home page Giter Site logo

bn-d / ppx_subliner Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 0.0 548 KB

[@@ deriving] plugin to generate Cmdliner sub-command groups, and ppx rewriter to generate Cmdliner evaluations.

Home Page: https://boni.ng/ppx_subliner/ppx_subliner/index.html

License: MIT License

OCaml 100.00%
ocaml ppxlib

ppx_subliner's People

Contributors

bn-d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ppx_subliner's Issues

invalid handling of parameters in modules

This happens when I try to have a parameter in a module instead of the toplevel. The code that computes the cmdliner term for a type doesn't account for qualified types, I think.

Error message:

File "bin/main.ml", line 14, characters 9-12:
14 |   | B of B.t
              ^^^
Error: Unbound module B_cmdliner_term

Repro:

dune file:

(executable
 (public_name repr_ppxsubliner)
 (name main)
 (flags :standard -warn-error -a)
 (preprocess (pps ppx_deriving_cmdliner ppx_subliner))
 (libraries repr_ppxsubliner))

bin/main.ml:

module B = struct
  type t = {
    file: string; [@pos 0] [@docv "FILE"]
  }
  [@@deriving cmdliner]

  let run (self : t) : unit =
    Format.printf "RUN B@."
end

type cli =
  | Version
  | B of B.t
[@@deriving subliner]

let run (cli : cli) : unit =
  match cli with
  | Version -> Format.printf "version@."
  | B b -> B .run b

[%%subliner.cmds eval.cli <- run] [@@name "test"]

Can't mix subliner with other deriving in script

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.