From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id T77QKZNE9F9rWwAA0tVLHw (envelope-from ) for ; Tue, 05 Jan 2021 10:50:59 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id eN5HJZNE9F/BPQAA1q6Kng (envelope-from ) for ; Tue, 05 Jan 2021 10:50:59 +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 C64389401C0 for ; Tue, 5 Jan 2021 10:50:58 +0000 (UTC) Received: from localhost ([::1]:52194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwjRJ-0006X4-BR for larch@yhetil.org; Tue, 05 Jan 2021 05:19:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwjQg-0006Wq-Qx for guix-devel@gnu.org; Tue, 05 Jan 2021 05:19:06 -0500 Received: from sender4-of-o50.zoho.com ([136.143.188.50]:21052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwjQC-00055a-Fu for guix-devel@gnu.org; Tue, 05 Jan 2021 05:19:06 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1609841911; cv=none; d=zohomail.com; s=zohoarc; b=XjETguXl7bAIfHpIBdl93L8iUAlONcjxpSr0xV7J/BNjdNo8GUUCaT42Bwg7r91alUFS1CwWzdv8B4Eacm1VWMiGjQaW/OQQNCcSAo4zmvnwXqgsBBvRDXrYjC07mVxtt+x1tRk056+Q+BaYgYT1+M/ryUl1AgUSSw7eQuM2DoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609841911; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=1LazPKtsBcYm11AwlY7acvjO81AQFgqDED8ET6LNBgI=; b=akuSI09u2yKPmZIdtmCXHLrQ7u6y/+ubGaJseQ2DVEWKo87ObVhhbQk6Bjicou6r7G8ZaMw2kSr0uAYz1rug/fBOxA1tjoezYtdcYKslG3Yue+joCKGK4VEyFYRwjoy3vhd2AHXyZs3qU61XsYySIxRSlGez7BdRJqK1/4nLQD4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1609841911; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=1LazPKtsBcYm11AwlY7acvjO81AQFgqDED8ET6LNBgI=; b=bzUMzXcksJu/DAsM3FkyT3JW6KAJA+JmmOCJKUOATPWMLhzw44+iYk7PJQ2biT3M Fh7tzRXLZ0eZnyYBfVve8NT2UqI4SYqb94CL5cUkk6iOS14LNzdi04IDcS6tKHGIaj7 TJvAYTj8VAnMmBdsrMfZ7t7kycTJ1Tf8nyMpgkQA= Received: from localhost (p54ad4779.dip0.t-ipconnect.de [84.173.71.121]) by mx.zohomail.com with SMTPS id 1609841909111613.0880609370245; Tue, 5 Jan 2021 02:18:29 -0800 (PST) From: Ricardo Wurmus To: guix-devel@gnu.org Message-ID: <20210105101817.7576-1-rekado@elephly.net> Subject: [PATCH] Discover extensions via GUIX_EXTENSIONS_PATH. Date: Tue, 5 Jan 2021 11:18:17 +0100 X-Mailer: git-send-email 2.29.2 In-Reply-To: <87blf4woei.fsf@gnu.org> References: <87blf4woei.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.50; envelope-from=rekado@elephly.net; helo=sender4-of-o50.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 1.66 Authentication-Results: aspmx1.migadu.com; dkim=fail (headers rsa verify failed) header.d=elephly.net header.s=zoho header.b=bzUMzXck; arc=reject (signature check failed: fail, {[1] = sig:zohomail.com:reject}); dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: C64389401C0 X-Spam-Score: 1.66 X-Migadu-Scanner: scn0.migadu.com X-TUID: uTAX2R8jDFyQ * guix/scripts.scm (%command-categories): Add extension category. * guix/ui.scm (command-files): Accept an optional directory argument. (extension-directories): New procedure. (commands): Use it. (show-guix-help): Hide empty categories. (run-guix-command): Try loading an extension if there is no Guix command. --- guix/scripts.scm | 4 +++- guix/ui.scm | 60 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/guix/scripts.scm b/guix/scripts.scm index 9792aaebe9..34cba35401 100644 --- a/guix/scripts.scm +++ b/guix/scripts.scm @@ -3,6 +3,7 @@ ;;; Copyright =C2=A9 2014 Deck Pickard ;;; Copyright =C2=A9 2015, 2016 Alex Kost ;;; Copyright =C2=A9 2020 Jan (janneke) Nieuwenhuizen +;;; Copyright =C2=A9 2021 Ricardo Wurmus ;;; ;;; This file is part of GNU Guix. ;;; @@ -86,7 +87,8 @@ (development (G_ "software development commands")) (packaging (G_ "packaging commands")) (plumbing (G_ "plumbing commands")) - (internal (G_ "internal commands"))) + (internal (G_ "internal commands")) + (extension (G_ "extension commands"))) =20 (define-syntax define-command (syntax-rules (category synopsis) diff --git a/guix/ui.scm b/guix/ui.scm index 0a1c9bd615..2ecfb53c7b 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -2046,24 +2046,36 @@ contain a 'define-command' form." (_ (loop))))))) =20 -(define (command-files) +(define* (command-files #:optional directory) "Return the list of source files that define Guix sub-commands." - (define directory - (and=3D> (search-path %load-path "guix.scm") - (compose (cut string-append <> "/guix/scripts") - dirname))) + (define directory* + (or directory + (and=3D> (search-path %load-path "guix.scm") + (compose (cut string-append <> "/guix/scripts") + dirname)))) =20 (define dot-scm? (cut string-suffix? ".scm" <>)) =20 - (if directory - (map (cut string-append directory "/" <>) - (scandir directory dot-scm?)) + (if directory* + (map (cut string-append directory* "/" <>) + (scandir directory* dot-scm?)) '())) =20 +(define (extension-directories) + "Return the list of directories containing Guix extensions." + (filter-map (lambda (directory) + (let ((scripts (string-append directory "/guix/scripts"))) + (and (file-exists? scripts) scripts))) + (parse-path + (getenv "GUIX_EXTENSIONS_PATH")))) + (define (commands) "Return the list of commands, alphabetically sorted." - (filter-map source-file-command (command-files))) + (filter-map source-file-command + (append (command-files) + (append-map command-files + (extension-directories))))) =20 (define (show-guix-help) (define (internal? command) @@ -2098,9 +2110,14 @@ Run COMMAND with ARGS.\n")) (('internal . _) #t) ;hide internal commands ((category . synopsis) - (format #t "~% ~a~%" (G_ synopsis)) - (display-commands (filter (category-predicate category) - commands)))) + (let ((relevant-commands (filter (category-predicate cate= gory) + commands))) + ;; Only print categories that contain commands. + (match relevant-commands + ((one . more) + (format #t "~% ~a~%" (G_ synopsis)) + (display-commands relevant-commands)) + (_ #f))))) categories)) (show-bug-report-information)) =20 @@ -2111,10 +2128,21 @@ found." (catch 'misc-error (lambda () (resolve-interface `(guix scripts ,command))) - (lambda - - (format (current-error-port) - (G_ "guix: ~a: command not found~%") command) - (show-guix-usage)))) + (lambda _ + ;; Check if there is a matching extension. + (catch 'misc-error + (lambda () + (match (search-path (extension-directories) + (format #f "~a.scm" command)) + (file + (load file) + (resolve-interface `(guix scripts ,command))) + (_ + (throw 'misc-error)))) + (lambda _ + (format (current-error-port) + (G_ "guix: ~a: command not found~%") command) + (show-guix-usage)))))) =20 (let ((command-main (module-ref module (symbol-append 'guix- command)))) --=20 2.29.2