Are this docopt bindings good enough to publish?

interop

#1

Hello,

I just created some very basic bindings for docopt library for a personal project. This is a library that makes the creation of cli programs very easy, you just provide a help string and it parses and reads the arguments accordingly, then it just returns an object.

Here are my bindings: https://github.com/danielo515/reason-rancher-cli/blob/feature/sumtTypes/src/Docopt.re

It is a Functor because I don’t know beforehand the possible return type of the docopt library, so I have to accept them as an argument.
Also I’m still not sure how can I accept a nullable string from Ocaml/Reason, that’s why version is not yet supported
I am looking for a better way of doing this if there is any.

Should I publish those bindings ? I can even provide some usage examples because… I’m actually using it :smile:

Thanks for your advise
Regards


#2

Ok, for the nullable (and optional) string I have the following options:

I can use option(string) on the type declaration or use the available nullable stuff.
The advantage of using just option is that it does not require any conversion and no runtime overhead.
The only problem could be that it is translated to undefined instead of null. In this case, it seems to work fine because the target library seems to don’t care about it being null or undefined, but there are cases where this may not suffice.

So just doing:

    [@bs.deriving abstract]
    type options = {
        help: bool,
        version: option(string),
        options_first: bool,
        exit: bool,
    };
    
    [@bs.module "docopt"] [@bs.val]
    external docopt: (string, options) => T.t = "docopt";
    
    let parse = (~help=true, ~options_first=false, ~exit=true, ~version=? , doc) =>
    docopt(doc, options(~help, ~options_first, ~version, ~exit));

Seems to fit the bill for this particular case, but I think it will be more correct to do

    [@bs.deriving abstract]
    type options = {
        help: bool,
        version: Js.nullable(string),
        options_first: bool,
        exit: bool,
    };
    
    [@bs.module "docopt"] [@bs.val]
    external docopt: (string, options) => T.t = "docopt";
    
    let parse = (~help=true, ~options_first=false, ~exit=true, ~version=? , doc) =>
    docopt(doc, options(~help, ~options_first, ~version=Js.Nullable.fromOption(version), ~exit));

But the generated JS requires external libraries, function conversion and I don’t think it deserves the extra cost