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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 414317EEBF for ; Mon, 3 Aug 2015 18:54:15 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of bmillwood@janestreet.com) identity=pra; client-ip=38.105.200.112; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="bmillwood@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of bmillwood@janestreet.com designates 38.105.200.112 as permitted sender) identity=mailfrom; client-ip=38.105.200.112; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="bmillwood@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mxout1.mail.janestreet.com) identity=helo; client-ip=38.105.200.112; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="postmaster@mxout1.mail.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0ByAQCIm79VnHDIaSZbGQEBAYIxgSFjBgaDHbkFghAdAQGGAQKBKgdMAQEBAQEBEgEBAQEBBhYJT4QkAQEBAgESEQQZAQE3AQQLCws3AgIiEgEFARwZIogECAMFpwGBLj4xik9whGUBBZEAAQEBAQEBAQEBAQEBAQEBAQEBAQEBEQYKi0WFCAeCLgwvEoExlH6Ee4dRgUeQXINBghgSI4EXEQaEDW4MAQGCPgEBAQ X-IPAS-Result: A0ByAQCIm79VnHDIaSZbGQEBAYIxgSFjBgaDHbkFghAdAQGGAQKBKgdMAQEBAQEBEgEBAQEBBhYJT4QkAQEBAgESEQQZAQE3AQQLCws3AgIiEgEFARwZIogECAMFpwGBLj4xik9whGUBBZEAAQEBAQEBAQEBAQEBAQEBAQEBAQEBEQYKi0WFCAeCLgwvEoExlH6Ee4dRgUeQXINBghgSI4EXEQaEDW4MAQGCPgEBAQ X-IronPort-AV: E=Sophos;i="5.15,602,1432591200"; d="scan'208";a="172544659" Received: from mxout1.mail.janestreet.com ([38.105.200.112]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 03 Aug 2015 18:54:14 +0200 Received: from tot-qpr-mailcore2.delacy.com ([172.27.56.106] helo=tot-qpr-mailcore2) by mxout1.mail.janestreet.com with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82) (envelope-from ) id 1ZMJ09-0005YQ-1n for caml-list@inria.fr; Mon, 03 Aug 2015 12:54:13 -0400 X-JS-Flow: external Received: by tot-qpr-mailcore2 with JS-mailcore (0.1) (envelope-from ) id BVv5y1-AAACkW-AW; 2015-08-03 12:54:13.011984-04:00 Received: from mail-qg0-f54.google.com ([209.85.192.54]) by mxgoog1.mail.janestreet.com with esmtps (UNKNOWN:AES128-GCM-SHA256:128) (Exim 4.72) (envelope-from ) id 1ZMJ08-0003o7-UK for caml-list@inria.fr; Mon, 03 Aug 2015 12:54:12 -0400 Received: by qgeh16 with SMTP id h16so92364456qge.3 for ; Mon, 03 Aug 2015 09:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Bqxb4yBE1ZWPjedPRtJblPi3i8WN9Rt4i1CFs1PpPFc=; b=Z87gkJKqc6Clx9RhHZM0vSuAYKm+pMQYzGOFsavNg9MQZ+ECh6FgK0PRvUx0o9xFbP WCizvcnaqtJDZ4jS6FDYS13xIkBIupSJqONYXxi9X3H4qj7zZthNmyv1VimMkZ9RouuV wZrwBer0ME7FWR3XXtU3vajXtuAEY/aMWT6Dw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=Bqxb4yBE1ZWPjedPRtJblPi3i8WN9Rt4i1CFs1PpPFc=; b=iDrbfMji9OiM4RTdRO/hpdFc/qyNdIEQjPGudWtzOmFqKS8OIyG+EnpLPxQT0/l+nU BXyO/Fz9L3m/P+wCrCiYDYyT5sZ8ji0zTY8vWxhdj6PAHNcfL7iFodkr9CBQyFJxrN3G tHwyuLpEhcp/MI6ZGFVeLTsYm4/bk9mQNPUEPJwBW/7ZVpCaQOaE8wLKJ+IiHHfGdofr F/Nl6oxqihF6bWrV4+XHp+igPkTEwTzDY1k/ncQITaqPLurf9x86E4Ox15eOVlvTJO2o 3Y18rZJRnKSOyG/t/f9YgJRhWIFtwho8JsrFS4mQ71gv8KSVPsj+VIkRoI+SE5VTD4kZ E5Ew== X-Gm-Message-State: ALoCoQnDlybko20YBT7d/0qY2kOoqz3i6YOuOuT8oKcnwgyDY4y4JYNrX+vz3SBK4Tgy3XBnzGBULFZ27PQERszjo5NMB3GTHYBM4aknpH7flr7zpOW1Y5mZXemKGsCNorSHowjsdKAn X-Received: by 10.140.34.33 with SMTP id k30mr25828339qgk.56.1438620852691; Mon, 03 Aug 2015 09:54:12 -0700 (PDT) X-Received: by 10.140.34.33 with SMTP id k30mr25828328qgk.56.1438620852589; Mon, 03 Aug 2015 09:54:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.96.142.106 with HTTP; Mon, 3 Aug 2015 09:53:53 -0700 (PDT) In-Reply-To: References: From:Ben Millwood Date: Mon, 3 Aug 2015 17:53:53 +0100 Message-ID: To:leowzukw@vmail.me Cc:caml users Content-Type: multipart/alternative; boundary=001a11c0b2cee2b0e4051c6b0435 X-JS-Processed-by: mailcore Subject: Re: [Caml-list] Using common arguments with Command module of the Core library --001a11c0b2cee2b0e4051c6b0435 Content-Type: text/plain; charset=UTF-8 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 > > > > 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 > File "cmd.ml", line 98, characters 5-44: > Warning 48: implicit elimination of optional argument ?extend > File "cmd.ml", line 49, characters 11-341: > Warning 27: unused variable summary. > File "cmd.ml", line 49, characters 20-341: > Warning 27: unused variable args. > Finished, 3 targets (0 cached) in 00:00:03. > > > Thanks for your help > Leo > > --001a11c0b2cee2b0e4051c6b0435 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
There are a few ways of doing this. The newly-added Applic= ative interface is worth showing off:

let shared_params = =3D
=C2=A0 let open Command.Param in
=C2=A0 return (fun= v c rcfile ->
=C2=A0 =C2=A0 verb :=3D v;
=C2=A0 =C2= =A0 color :=3D c;
=C2=A0 =C2=A0 rcfile)
=C2=A0 =C2=A0 &= lt;*> flag "-v" (optional_with_default 0 int) ~doc:"...&q= uot;
=C2=A0 =C2=A0 <*> flag "-c" (...) ~doc:"= ;..."
=C2=A0 =C2=A0 <*> ...

s= hared_params is now a package of arguments that sets the verb and color ref= s 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). Y= ou can use it in Command.basic as follows:

let sum= =3D
=C2=A0 Command.basic
=C2=A0 =C2=A0 ~summary:"= whatever"
=C2=A0 =C2=A0 Command.Spec.(
=C2=A0 =C2= =A0 =C2=A0 empty
=C2=A0 =C2=A0 =C2=A0 +> shared_params
=C2=A0 =C2=A0 =C2=A0 +> anon ...)
=C2=A0 =C2=A0 =C2=A0 (fun= rc ... () -> ...)

let main () =3D
= =C2=A0 Command.run begin
=C2=A0 =C2=A0 Command.group ~summary:&qu= ot;some stuff"
=C2=A0 =C2=A0 =C2=A0 [ "sum", sum
=C2=A0 =C2=A0 =C2=A0 ; "settings", ...
=C2=A0 = =C2=A0 =C2=A0 ]
=C2=A0=C2=A0end

Let me k= now if I've omitted too much :)
<= br>
On 3 August 2015 at 13:18, <leowzukw@vmail.= me> wrote:

Hello everybody,<= /span>

I= 9;m trying to use subcommands with the Core library. I would like to factor= ize 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.

=C2=A0

Main problem is t= hat I can't define more arguments to my subcommand.=C2=A0More details i= n my code, which is joined. You may also find it here (Github gist, could b= e updated): http://j.mp/1= JHlZ6S

=C2=A0

Result of the com= pilation (corebuild cmd.byte)


+ ocamlf= ind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -s= hort-paths -thread -syntax camlp4o -package bin_prot.syntax -package sexpli= b.syntax,comparelib.syntax,fieldslib.syntax,variantslib.syntax -package cor= e -o cmd.cmo cmd.ml<= br>File "<= a href=3D"http://cmd.ml" target=3D"_blank">cmd.ml", line 98, chara= cters 5-44:
Warning 48: implicit elimination of optional argument ?extend=
File "= cmd.ml", line 49, char= acters 11-341:
Warning 27: unused variable summary.
File "cmd.ml", line 49, characters 20-341:<= br>Warning 27: = unused variable args.
Finished, 3 targets (0 cached) in 00:00:03.


Thanks for your help
Leo

=C2=A0

--001a11c0b2cee2b0e4051c6b0435--