From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 69C0F7EEBF for ; Tue, 4 Aug 2015 19:23:49 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of leowzukw@vmail.me) identity=pra; client-ip=62.210.82.129; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="leowzukw@vmail.me"; x-sender="leowzukw@vmail.me"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of leowzukw@vmail.me designates 62.210.82.129 as permitted sender) identity=mailfrom; client-ip=62.210.82.129; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="leowzukw@vmail.me"; x-sender="leowzukw@vmail.me"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Fail (mail3-smtp-sop.national.inria.fr: domain of postmaster@mx1.vmail.me does not designate 62.210.82.129 as permitted sender) identity=helo; client-ip=62.210.82.129; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="leowzukw@vmail.me"; x-sender="postmaster@mx1.vmail.me"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DWDADT9MBVU4FS0j5bgk1NVGMGqTCTD4IuhgECgTtMAQEBAQEBBwEXCwoFIjCEIwEBAQMBIwQGEwEBLAsBBAsEBw4KHA4CAgJBFAYTCBOICwwEtCRwhGUBBZFNAQEBAQEBAQEBAQEBAQEBAQEBAQEBEQaEWYZ2hG0bB4JpgUOMUYgugjqCQ4dTgUdGkB0Fg0KDZBGEFDwxDAEBgj4BAQE X-IPAS-Result: A0DWDADT9MBVU4FS0j5bgk1NVGMGqTCTD4IuhgECgTtMAQEBAQEBBwEXCwoFIjCEIwEBAQMBIwQGEwEBLAsBBAsEBw4KHA4CAgJBFAYTCBOICwwEtCRwhGUBBZFNAQEBAQEBAQEBAQEBAQEBAQEBAQEBEQaEWYZ2hG0bB4JpgUOMUYgugjqCQ4dTgUdGkB0Fg0KDZBGEFDwxDAEBgj4BAQE X-IronPort-AV: E=Sophos;i="5.15,610,1432591200"; d="ml'?scan'208,217";a="142021351" Received: from mx1.vmail.me ([62.210.82.129]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Aug 2015 19:23:20 +0200 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=vmail.me; s=mx1; t=1438709152; bh=EQDndRqS8cT+hw///fJ6Eo41e69hoXL9IiHCQkM4UWs=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=EXvk26HOyeugSAw23esJ1UOiKwopNMFb7B93BM5HgFvLJX3q364RIXFA4HoWMOUvV XER+BrEah0K/DfMaNSe8b8fxLx2sx/wUz4ap+qemBHeVQjqI3ln4i8GfivZU25D1VR RTw+4NsV+jdsX8d6PdYpIEvQf7b5yDNpGdnNZhtvRCiNfW3qAVEuYfW+rWSAYQReC8 Aha8Q5nds/pvtx03Tofi2bJup8FuQN/B2CN2RbsiVkUt0V097fTVkSo5ju2KTqNtZO gnipxdc4lAFeIzFrD866J2Oh6fcKnbOKmy7dC0Gq/J+fG5J9U01LBFnshGLiViAl+X uVk86kuu4xcZQ== Content-Type: multipart/mixed; boundary="=_2ebb175dfbfa86fffc67622f7a620761" Date: Tue, 04 Aug 2015 19:25:52 +0200 From: leowzukw@vmail.me To: Ben Millwood Cc: caml-list@inria.fr In-Reply-To: References: <05d254b1bbdff3c0030bcc8b85e1c951@vmail.me> Message-ID: X-Sender: leowzukw@vmail.me Subject: Re: [Caml-list] Using common arguments with Command module of the Core library --=_2ebb175dfbfa86fffc67622f7a620761 Content-Type: multipart/alternative; boundary="=_066c1f272044e6ee6960b2a6bd6160c6" --=_066c1f272044e6ee6960b2a6bd6160c6 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 I installed 112.35.01 and now it works perfectly, both the installation and your solution. I join the working code for mailing list. I also updated the gist. Thanks a lot for your help Leo Le 2015-08-04 10:34, Ben Millwood a écrit : > Make sure you are installing core 112.35.01, not 112.35.00. I believe it contains a fix for the issue you're seeing. If it doesn't, let me know and I'll look into it a little more. > > On 3 August 2015 at 19:54, wrote: > > Thanks for your quick answer. It seems clear enough. > > Unfortunately, I can't install latest version of core, I get this error > > # File "src/iobuf.ml [1]", line 624, characters 17-28: > # Integer literal exceeds the range of representable integers of type int > > I think it's because of my 32bit computer. I will keep your solution in mind until I could get the latest version of core. > > Leo > > PS: Should I report an issue on Github for that ? In opam or core repository ? > > Le 2015-08-03 18:53, Ben Millwood a écrit : > There are a few ways of doing this. The newly-added Applicative interface is worth showing off: > > let shared_params = > let open Command.Param in > return (fun v c rcfile -> > verb := v; > color := c; > rcfile) > <*> flag "-v" (optional_with_default 0 int) ~doc:"..." > <*> flag "-c" (...) ~doc:"..." > <*> ... > > shared_params is now a package of arguments that sets the verb and color refs and then gives you the rcfile (it's only that way to mirror your code; I'd usually prefer to just put all three in a record or something). You can use it in Command.basic as follows: > > let sum = > Command.basic > ~summary:"whatever" > Command.Spec.( > empty > +> shared_params > +> anon ...) > (fun rc ... () -> ...) > > let main () = > Command.run begin > Command.group ~summary:"some stuff" > [ "sum", sum > ; "settings", ... > ] > end > > Let me know if I've omitted too much :) > > On 3 August 2015 at 13:18, wrote: > > Hello everybody, > > I'm trying to use subcommands with the Core library. I would like to factorize several things : > > * A set of common arguments (to set color, verbosity and so on) > * A common way to deal with these arguments > * A pretty way to define subcommands using these common arguments and way to handle it. > > Main problem is that I can't define more arguments to my subcommand. More details in my code, which is joined. You may also find it here (Github gist, could be updated): http://j.mp/1JHlZ6S [2] > > Result of the compilation (corebuild cmd.byte) > > + ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -syntax camlp4o -package bin_prot.syntax -package sexplib.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package core -o cmd.cmo cmd.ml [3] > File "cmd.ml [3]", line 98, characters 5-44: > Warning 48: implicit elimination of optional argument ?extend > File "cmd.ml [3]", line 49, characters 11-341: > Warning 27: unused variable summary. > File "cmd.ml [3]", line 49, characters 20-341: > Warning 27: unused variable args. > Finished, 3 targets (0 cached) in 00:00:03. > > Thanks for your help > Leo Links: ------ [1] http://iobuf.ml [2] http://j.mp/1JHlZ6S [3] http://cmd.ml --=_066c1f272044e6ee6960b2a6bd6160c6 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

I installed 112.35.01 and now it works perfectly, both the installation = and your solution.

I join the working code for mailing list. I also updated the gist.

 

Thanks a lot for your help

Leo

 

Le 2015-08-04 10:34, Ben Millwood a écrit :

Make sure you are installing core 112.35.01, not 112.35.00= . I believe it contains a fix for the issue you're seeing. If it doesn't, l= et me know and I'll look into it a little more.

On 3 August 2015 at 19:54, <leowzukw@vmail.me> wrote:

Thanks for your quick answer. It seems clear enough.

Unfortunately, I can't install latest version of core, I get this error<= /p>

# File "src/iobuf.ml", line 624, characters 17-28:
# I= nteger literal exceeds the range of representable integers of type int

I think it's because of my 32bit computer. I will keep your solution in = mind until I could get the latest version of core.

Leo

PS: Should I report an issue on Github for that ? In opam or core reposi= tory ?

 

Le 2015-08-03 18:53, Ben Millwood a écrit :

There are a few ways of doing this. The newly-added Applic= ative interface is worth showing off:
 
let shared_params =3D
  let open Command.Param in
  return (fun v c rcfile ->
    verb :=3D v;
    color :=3D c;
    rcfile)
    <*> flag "-v" (optional_with_default 0 int) ~doc:"= ..."
    <*> flag "-c" (...) ~doc:"..."
    <*> ...
 
shared_params is now a package of arguments that sets the verb and col= or refs and then gives you the rcfile (it's only that way to mirror your co= de; I'd usually prefer to just put all three in a record or something). You= can use it in Command.basic as follows:
 
let sum =3D
  Command.basic
    ~summary:"whatever"
    Command.Spec.(
      empty
      +> shared_params
      +> anon ...)
      (fun rc ... () -> ...)
 
let main () =3D
  Command.run begin
    Command.group ~summary:"some stuff"
      [ "sum", sum
      ; "settings", ...
      ]
  end
 
Let me know if I've omitted too much :)

On 3 August 2015 at 13:18, <leowzukw@vmail.me> wrote:

Hello everybody= ,

I'm trying to use subcommands with the Core library. I would like to fa= ctorize several things :

  • A set of commo= n arguments (to set color, verbosity and so on)
  • A common way t= o deal with these arguments
  • A pretty way t= o define subcommands using these common arguments and way to handle it.

 

Main problem is= that I can't define more arguments to my subcommand. More details in = my code, which is joined. You may also find it here (Github gist, could be = updated): http://j.mp/1JHlZ6S

 

Result of the c= ompilation (corebuild cmd.byte)


+ ocamlfind = ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short= -paths -thread -syntax camlp4o -package bin_prot.syntax -package sexplib.sy= ntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package core -o= cmd.cmo cmd.ml
File "cmd.ml= ", line 98, characters 5-44:
Warning 48: implicit elimination of optional argume= nt ?extend
cmd.ml", line 49, characters 11-341:<= /span>
Warning 2= 7: unused variable summary.
File "cmd.ml", line 49, ch= aracters 20-341:
Warning 27: unused variable args.
Finished, 3 targets (0 cached) in 00:00:03= .


Thanks for your help
Leo

 

 

 

 

 
--=_066c1f272044e6ee6960b2a6bd6160c6-- --=_2ebb175dfbfa86fffc67622f7a620761 Content-Transfer-Encoding: base64 Content-Type: text/plain; name=cmd.ml Content-Disposition: attachment; filename=cmd.ml; size=2205 KCogQnVpbGQgd2l0aDoKICAqIGNvcmVidWlsZCBjbWQuYnl0ZSAqKQoKCm9w ZW4gQ29yZS5TdGQ7OwoKKCogV2l0aCB0aGlzIGNvZGUsIHdlIGFyZSB0cnlp bmcgdG8KICogRGVmaW5lIGEgY29tbW9uIHNldCBvZiBhcmd1bWVudHMgdG8g YmUgcGFzc2VkIHRvIGFsbCBzdWIgY29tbWFuZHMKICogSGFuZGxlIHRoZXNl IGNvbW1vbiBhcmd1bWVudHMgYWxsIHRoZSBzYW1l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iBUd28gc3ViIGNvbW1hbmRzICop CgooKiBEaXNwbGF5IHRoZSBzdW0gb2YgdGhlIGFyZ3VtZW50cyAqKQpsZXQg c3VtID0KICAoCiAgICAgICJzdW0iCiAgICAgICwKICAgIENvbW1hbmQuYmFz aWMgfnN1bW1hcnk6IiIKICAgICAgQ29tbWFuZC5TcGVjLigKICAgICAgICBl bXB0eQogICAgICAgICs+IHNoYXJlZF9wYXJhbXMKICAgICAgICArPiBhbm9u ICgiZmlyc3RfbnVtYmVyIiAlOiBpbnQpCiAgICAgICAgKz4gYW5vbiAoInNl Y29uZF9udW1iZXIiICU6IGludCkKICAgICAgKQogICAgICAoZnVuIHJjIGEg YiAoKSAtPiAoKiBYWFggU3RyYW5nZSBhcmd1bWVudHMgcGFzc2VkIGhlcmUg KikKICAgICAgICAoKiBXZSB3b3VsZCBsaWtlIHRvIGdldCB0aGUgbnVtYmVy cyBwYXNzZWQgaW4gYXJndW1lbnRzICgiZmlyc3QKICAgICAgICAgKiBudW1i ZXIiCiAgICAgICAgICogYW5kICJzZWNvbmQgbnVtYmVyIiBiZWxvdykgKikK ICAgICAgICBhICsgYiB8PiBwcmludGYgIiVpXG4iOwogICAgICAgICgqIFNv bWUgY29kZSB0byB1c2UgY29tbW9uIGFyZ3VtZW50cyAqKQogICAgICAgIGlm ICFjb2xvciB0aGVuIHByaW50ZiAiQ29sb3JlZFxuIiBlbHNlCiAgICAgICAg ICBwcmludF9lbmRsaW5lIHJjKQogICkKOzsKCigqIFByaW50IHNvbWUgc2V0 dGluZ3MgYW5kIGEgbnVtYmVyIHBhc3NlZCB0byB0aGUgcHJvZ3JhbSAqKQps ZXQgc2V0dGluZ3MgPQogICgKICAgICAic2V0dGluZ3MiCiAgICAgLAogICAg IENvbW1hbmQuYmFzaWMgfnN1bW1hcnk6IkRpc3BsYXkgc2V0dGluZ3MiCiAg ICAgIENvbW1hbmQuU3BlYy4oCiAgICAgICAgIGVtcHR5CiAgICAgICAgICs+ IHNoYXJlZF9wYXJhbXMKICAgICAgICAgKz4gYW5vbiAobWF5YmUgKCJhIG51 bWJlciIgJTogaW50KSkKICAgICAgKQogICAgICAoZnVuIHJjIG4gKCkgLT4K ICAgICAgICBwcmludGYgIm46ICVpXG4iIChPcHRpb24udmFsdWUgfmRlZmF1 bHQ6MCBuKTsKICAgICAgICBwcmludGYgIlxuU2V0dGluZ3NcbiI7CiAgICAg ICAgcHJpbnRmICJSYzogJXNcbiIgcmM7CiAgICAgICAgcHJpbnRmICJDb2xv cjogJWJcbiIgIWNvbG9yKQogICkKOzsKCmxldCAoKSA9CiAgbGV0IG9wZW4g Q29tbWFuZCBpbgogIHJ1biBiZWdpbgogICAgZ3JvdXAgfnN1bW1hcnk6IkEg cHJvZ3JhbSB0byB0ZXN0IiBbIHN1bSA7IHNldHRpbmdzIF0KICBlbmQKOzsK --=_2ebb175dfbfa86fffc67622f7a620761--