From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6PIKEKPkT1/FJwAA0tVLHw (envelope-from ) for ; Wed, 02 Sep 2020 18:29:55 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id oHS8C6PkT18kNQAAbx9fmQ (envelope-from ) for ; Wed, 02 Sep 2020 18:29:55 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C079E940602 for ; Wed, 2 Sep 2020 18:29:54 +0000 (UTC) Received: from localhost ([::1]:55808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDXW5-0007d1-N0 for larch@yhetil.org; Wed, 02 Sep 2020 14:29:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDXRO-0005Ro-OM for guix-patches@gnu.org; Wed, 02 Sep 2020 14:25:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49136) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDXRO-0002Sb-Eb for guix-patches@gnu.org; Wed, 02 Sep 2020 14:25:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kDXRO-0005yz-AV for guix-patches@gnu.org; Wed, 02 Sep 2020 14:25:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#43159] [PATCH 1/2] scripts: Use 'define-command' and have 'guix help' use that. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 02 Sep 2020 18:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43159 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 43159@debbugs.gnu.org Received: via spool by 43159-submit@debbugs.gnu.org id=B43159.159907106822954 (code B ref 43159); Wed, 02 Sep 2020 18:25:02 +0000 Received: (at 43159) by debbugs.gnu.org; 2 Sep 2020 18:24:28 +0000 Received: from localhost ([127.0.0.1]:60682 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kDXQq-0005yA-9w for submit@debbugs.gnu.org; Wed, 02 Sep 2020 14:24:28 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:39775) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kDXQo-0005xw-3z for 43159@debbugs.gnu.org; Wed, 02 Sep 2020 14:24:26 -0400 Received: by mail-qt1-f194.google.com with SMTP id 92so4331996qtb.6 for <43159@debbugs.gnu.org>; Wed, 02 Sep 2020 11:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=SoVQ4+rAgpIg90+4guBmGn0lLf9ZRNJP/sdsAKqAQWE=; b=bZta9C1q60WHu0Qj4jQIUd/hQLrSiywaijhdLST0Oj48KCJDAY455J8zBS5/bVhg9h pJghcwa8Aqo23yq+5sXEtgN1QWg0Me5BZLK0Tjk4RBMAr0IqW1IopZjVfe6ZokqSB0t/ tFn4Ektqt16I4RaA2L0OjThqaPU5pEUwzAiOzNZv3cZllma5peM+g2J8qBwB4lVlLLsn 5SwFOsJvPS91rbY3r2OxmN0o2USIbYrFHKdvQVluCXRDfQaDwFcIP7voKhE6VORXfCMZ AbGuTKn866iq+wh3YJ2d7G+BqcoHSk4fGPG5iTKmNtAUIsF2+gvGqtO6Z3mNULGnGd/C XxNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=SoVQ4+rAgpIg90+4guBmGn0lLf9ZRNJP/sdsAKqAQWE=; b=UTB/aVPp6ItVtRVGc7KjaaHMK4nCmtuZy7JQ/BzOpfBoh8fWIAnbQGkWRgXsGTDsOw hn1BBmcOWIiEU8xwfNn5nzXw9QIfh1AW1zq7XutZQKKMSt10AdYJ8thUkiaYDBRX4rxf vdfJd0lOUFojeQRg0Co4Y/lDDZLOi5JaUbis01rx+xk1fOO7ubGRib1U4CRmJt5shg0J /bdjCQgnqGx0NLHns3MlatzfiyoEWsXW5LU8Axtcy6yHEwqS1y7YECj6m8XI803hk3Ow krlF8YeYmxQOwDOPJcQcQmujRKaQN/LXkEAtJcRLaV5bemLGatmcmfDdpgToLOIfUpWy hidw== X-Gm-Message-State: AOAM530xc8PdN0YpRZdoR4CH/aNTmnx+Dh6RC+s0eRkucRVtzXDhTunn kyoKfC0IjUWE4ZBRVy51zOlr0YtlPl0Ibg== X-Google-Smtp-Source: ABdhPJw6isFA4MJE9G02iHf8lXMCw4wtqzZEedRf81RvCQsqFBacLqTuIi7ReIU2jr4hHg/kyGkyuA== X-Received: by 2002:aed:3223:: with SMTP id y32mr8047690qtd.341.1599071060313; Wed, 02 Sep 2020 11:24:20 -0700 (PDT) Received: from hurd (dsl-10-133-254.b2b2c.ca. [72.10.133.254]) by smtp.gmail.com with ESMTPSA id u18sm143528qtk.61.2020.09.02.11.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 11:24:19 -0700 (PDT) From: Maxim Cournoyer References: <20200901203520.21103-1-ludo@gnu.org> <20200901204136.21375-1-ludo@gnu.org> Date: Wed, 02 Sep 2020 14:24:34 -0400 In-Reply-To: <20200901204136.21375-1-ludo@gnu.org> ("Ludovic \=\?utf-8\?Q\?Cou\?\= \=\?utf-8\?Q\?rt\=C3\=A8s\=22's\?\= message of "Tue, 1 Sep 2020 22:41:35 +0200") Message-ID: <87r1rk595p.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.0 (-) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=bZta9C1q; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: /rWtBILTDG/G Ludovic Court=C3=A8s writes: > This changes 'guix help' to print a short synopsis for each command and > to group commands by category. [...] > diff --git a/guix/scripts.scm b/guix/scripts.scm > index 8534948892..013b775818 100644 > --- a/guix/scripts.scm > +++ b/guix/scripts.scm > @@ -34,7 +34,10 @@ > #:use-module (srfi srfi-19) > #:use-module (srfi srfi-37) > #:use-module (ice-9 match) > - #:export (args-fold* > + #:export (synopsis > + category > + define-command > + args-fold* > parse-command-line > maybe-build > build-package > @@ -50,6 +53,30 @@ > ;;; > ;;; Code: > > +;; Syntactic keywords. > +(define synopsis 'command-synopsis) > +(define category 'command-category) Are these definition really necessary/useful? I would have thought having category and synopsis understood as literals in the define-command syntax was enough? > +(define-syntax define-command > + (syntax-rules (category synopsis) > + "Define the given command as a procedure along with its synopsis and, > +optionally, its category. The synopsis becomes the docstring of the > +procedure, but both the category and synopsis are meant to be read (pars= ed) by > +'guix help'." > + ;; The (synopsis ...) form is here so that xgettext sees those strin= gs as > + ;; translatable. > + ((_ (name . args) > + (synopsis doc) body ...) > + (define (name . args) > + doc > + body ...)) > + ((_ (name . args) > + (category _) > + (synopsis doc) body ...) > + (define (name . args) > + doc > + body ...)))) > + > (define (args-fold* args options unrecognized-option-proc operand-proc .= seeds) > "A wrapper on top of `args-fold' that does proper user-facing error > reporting." > diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm > index f3b86fba14..8796774a01 100644 > --- a/guix/scripts/archive.scm > +++ b/guix/scripts/archive.scm > @@ -355,7 +355,10 @@ output port." > ;;; Entry point. > ;;; > > -(define (guix-archive . args) > +(define-command (guix-archive . args) > + (category advanced) It'd be helpful if the category was an enum to keep the set of categories focused and helpful. [...] > --- a/guix/scripts/weather.scm > +++ b/guix/scripts/weather.scm > @@ -495,7 +495,9 @@ SERVER. Display information for packages with at lea= st THRESHOLD dependents." > ;;; Entry point. > ;;; > > -(define (guix-weather . args) > +(define-command (guix-weather . args) > + (synopsis "report on the available of pre-built package binaries") ^ availability [...] > +(define (source-file-command file) > + "Read FILE, a Scheme source file, and return either a object= based > +on the 'define-command' top-level form found therein, or #f if FILE does= not > +contain a 'define-command' form." > + (define command-name > + (match (string-split file #\/) > + ((_ ... "guix" "scripts" name) > + (list (file-sans-extension name))) > + ((_ ... "guix" "scripts" first second) > + (list first (file-sans-extension second))))) It'd be better if an else clause threw an informative error, especially since the restriction on file name is not otherwise documented. > + ;; The strategy here is to parse FILE. This is much cheaper than a > + ;; technique based on run-time introspection where we'd load FILE and = all > + ;; the modules it depends on. Interesting! Have you measure it? I would have thought loading a couple optimized byte code modules could have been nearly as fast as parsing files manually. If so, I think it'd be preferable to use introspection rather than implement a custom parser. > + (call-with-input-file file > + (lambda (port) > + (let loop () > + (match (read port) > + (('define-command _ ('synopsis synopsis) > + _ ...) > + (command command-name synopsis 'main)) > + (('define-command _ > + ('category category) ('synopsis synopsis) > + _ ...) > + (command command-name synopsis category)) > + ((? eof-object?) > + #f) > + (_ > + (loop))))))) > + [...] > + (define (display-commands commands) > + (let* ((names (map (lambda (command) > + (string-join (command-name command))) > + commands)) > + (max-width (reduce max 0 (map string-length names)))) You can drop reduce and use (max (map string-length names)) instead. Maxim