From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: sirgazil Newsgroups: gmane.lisp.guile.user Subject: Re: Yet another command line DSL Date: Fri, 29 Dec 2017 19:34:04 -0500 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1514596696 13615 195.159.176.226 (30 Dec 2017 01:18:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 30 Dec 2017 01:18:16 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 To: Amirouche Boubekki , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Dec 30 02:18:07 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eV5mp-00030k-66 for guile-user@m.gmane.org; Sat, 30 Dec 2017 02:18:07 +0100 Original-Received: from localhost ([::1]:34136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eV5on-0004PZ-Tb for guile-user@m.gmane.org; Fri, 29 Dec 2017 20:20:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eV5oQ-0004Ox-Co for guile-user@gnu.org; Fri, 29 Dec 2017 20:19:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eV5oN-0001zO-8D for guile-user@gnu.org; Fri, 29 Dec 2017 20:19:46 -0500 Original-Received: from sender-pp-092.zoho.com ([135.84.80.237]:25390) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eV5oN-0001xI-0p for guile-user@gnu.org; Fri, 29 Dec 2017 20:19:43 -0500 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=subject:to:references:from:message-id:date:user-agent:mime-version:in-reply-to:content-type; b=KWta9kzSVlcmQyZDRUkQP8nHYKhn66e5NdnrgAgby3VWM90bvBuyHpAyWYh8a9wd7H0PZMijH7N1 ufZBCisGfIFjQNlygeXNvICfXoV21HtaXRTEqILJHZ0pqb575cUc Original-Received: from [192.168.1.51] (190.251.129.76 [190.251.129.76]) by mx.zohomail.com with SMTPS id 1514594045930950.2232482468586; Fri, 29 Dec 2017 16:34:05 -0800 (PST) In-Reply-To: Content-Language: en-US X-ZohoMailClient: External X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 135.84.80.237 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14390 Archived-At: On 28/12/17 16:50, Amirouche Boubekki wrote: > Héllo all, > > > I had to scratch an itch about command line interfaces again. > > In Python, I use http://docopt.org/ but it's pain (even if less > painful that argparse and click) because you have to manually > dispatch to the correct function based on a single dictionary > to the correct function. > > Long story short, I made a replacement for that, that should improve > the developper experience in guile. > > Here is an ascii video of the thing: > >    https://asciinema.org/a/VpSS5YTfEuKgAg0J6zwR9ZBxW > > It's guix related so you might be able to relate to it. > > At the end of the video the code and attached to this mail. > > Basically, the idea is to create a nested alist ie. a tree, > where leafs are procedures as specification for the cli. > > It looks like that: > > (define xote >   `((package >      (install ,package-install) >      (search ,package-search)) >     (system >      (init ,system-init) >      (reconfigure ,system-reconfigure) >      (generation >       (switch ,system-generation-switch) >       (list ,system-generation-list))))) > > I find it very pleasant to read. > > When the user type a command like: > >   xote package install guile@2.2.3 > > The the program will walk the spec and the program arguments > at the same time to look for a possible match. When it finds > a match it checks whether the user wants help otherwise it > executes the command with the rest of the program arguments > that are not matched. In the above example ``'("guile@2.2.3")'' > is passed as an arugment of the ``package-install'' procedure. > > What I plan to do next, is to provide a generic function that > will look for --optional=arguments in the rest and outputs > two lists: > > - an alist of --optional=arguments or short options like -K > > - again, the rest of the arguments that were not parsed as >   short or long options. > > This simple and generic implementation of arguments will require > the developer using this tool to validate the options if he really > wants. And will allow him to use his favorite cli tool for short > options... > > The end result is that we have the best of both world, pleasant > interface that organize its subcommands by topic and the liberty > to use a powerful other framework to parse optional flags. > > I find this approach clean and sleak. > > > WDYT? Thanks, Amirouche! I actually need this :) Nice :)