From: sirgazil <sirgazil@zoho.com>
To: Amirouche Boubekki <amirouche@hypermove.net>,
Guile User <guile-user@gnu.org>
Subject: Re: Yet another command line DSL
Date: Fri, 29 Dec 2017 19:34:04 -0500 [thread overview]
Message-ID: <ec083f95-46c8-7133-8426-802ed7543449@zoho.com> (raw)
In-Reply-To: <ea7f19ef68aaaa9c648d28cd3dd9e17e@hypermove.net>
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 :)
prev parent reply other threads:[~2017-12-30 0:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-28 21:50 Yet another command line DSL Amirouche Boubekki
2017-12-30 0:34 ` sirgazil [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec083f95-46c8-7133-8426-802ed7543449@zoho.com \
--to=sirgazil@zoho.com \
--cc=amirouche@hypermove.net \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).