From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oHlMIS9PB2CRUgAA0tVLHw (envelope-from ) for ; Tue, 19 Jan 2021 21:29:19 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id uDYwHS9PB2DVSQAAB5/wlQ (envelope-from ) for ; Tue, 19 Jan 2021 21:29:19 +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 0B2FB940341 for ; Tue, 19 Jan 2021 21:29:18 +0000 (UTC) Received: from localhost ([::1]:48702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1yYv-0004i0-RZ for larch@yhetil.org; Tue, 19 Jan 2021 16:29:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1yYg-0004fv-Bs for guix-patches@gnu.org; Tue, 19 Jan 2021 16:29:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40396) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1yYg-0008M5-4K for guix-patches@gnu.org; Tue, 19 Jan 2021 16:29:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1yYf-0005oi-Uj for guix-patches@gnu.org; Tue, 19 Jan 2021 16:29:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45893] [PATCH v3 3/3] ui: Add hint for command typo. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 19 Jan 2021 21:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45893 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45893@debbugs.gnu.org Received: via spool by 45893-submit@debbugs.gnu.org id=B45893.161109171022302 (code B ref 45893); Tue, 19 Jan 2021 21:29:01 +0000 Received: (at 45893) by debbugs.gnu.org; 19 Jan 2021 21:28:30 +0000 Received: from localhost ([127.0.0.1]:51938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1yY9-0005nS-Qy for submit@debbugs.gnu.org; Tue, 19 Jan 2021 16:28:30 -0500 Received: from mail-wr1-f52.google.com ([209.85.221.52]:43423) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1yY8-0005nF-KR for 45893@debbugs.gnu.org; Tue, 19 Jan 2021 16:28:28 -0500 Received: by mail-wr1-f52.google.com with SMTP id y17so21138453wrr.10 for <45893@debbugs.gnu.org>; Tue, 19 Jan 2021 13:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ej7JNNEa8ZWZW0jj2FCP8t+HXFmgK8Ieh9JBsR0FZgM=; b=J/IOY/vIYKdSUHqmOMNoKkN6e+ONDT9+G6XqS1NP/yMrupTHbdiX7JqwUzjBn/zDKy uqFkdQHHkzxdvjxm+h8o2lFFrVbHPrx56dMQTEt5a7TLfDwq1vEywR4gBX/aLp0AGlY0 DoggW6mORbKutJpJZ7etbusNoNdmVgYTza+VNI+qrc3ZSHosEQHrgL3tw9G9v/ATZqwk I8PMMjZPRKcA7+CnX0kx2uThH0DnLLqeJ6vFyWNo8mML24nQiIsh0OP7oHCKH+FprTcQ rJu7GHUquZ1bfBT14UfJwqehyZyQAYHP5qE5SXzjLuwEkZ/TYY2VwNJCBtMhj2I5sTB/ D/SA== 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:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ej7JNNEa8ZWZW0jj2FCP8t+HXFmgK8Ieh9JBsR0FZgM=; b=Zi+Tz41PFpJe9ldeMxffn4PFxf1ciQT4t/t7pp8Mf2rB+H5CfvFmgDQxPUb4HiJjmx D/+LO78uK2iL0o8YyD/xLgqPa68bNi5evcC/xaUdFmbkxOKJnruCG8bW4Rld6/kYlI5I /FS2PRWdn6bvDdIsOuuX/rUBEDhw3FPcWhBetxYt2BBFjQrqivQxh/AuVooeFCXSMyhs oivE9S2jWSOb1D7ZmF73NNLXq/p/d7d7L6EwWn8toI3nkPJK41gY6oducfCvOnibjF22 shYnF7tVQFtXdrD/uPww3NAVROuqhUMQT3h9mNDn0pa88xNDuElyT8L2ATrjvIXOFw5C HELg== X-Gm-Message-State: AOAM532ddK3X1CWOjqT7E2vwxVvj6BOEr5W2KHLknOb+ScK907wu7OxI Ccs69q86r2r/mPkglV5m7qsZfdC8XLI= X-Google-Smtp-Source: ABdhPJzlh3O/nikghLiZcBUQBO8PDO2wt9QoVMbAqNiU8NbTFlg8XFFjn2rLCDFZYP6y4SHWv7OGuA== X-Received: by 2002:a5d:40ce:: with SMTP id b14mr6055610wrq.350.1611091703186; Tue, 19 Jan 2021 13:28:23 -0800 (PST) Received: from lili.univ-paris-diderot.fr ([2a01:e0a:59b:9120:65d2:2476:f637:db1e]) by smtp.gmail.com with ESMTPSA id w8sm37844239wrl.91.2021.01.19.13.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jan 2021 13:28:22 -0800 (PST) From: zimoun Date: Tue, 19 Jan 2021 22:28:10 +0100 Message-Id: <20210119212810.20681-3-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210119212810.20681-1-zimon.toutoune@gmail.com> References: <20210119212810.20681-1-zimon.toutoune@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 2.75 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b="J/IOY/vI"; 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-Migadu-Queue-Id: 0B2FB940341 X-Spam-Score: 2.75 X-Migadu-Scanner: scn0.migadu.com X-TUID: Q+LRzkVJnTUD * guix/ui.scm (command-hint): New variable * guix/ui.scm (run-guix-command): Use it. --- guix/ui.scm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index bd504c68da..895c3a721f 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -2123,6 +2123,14 @@ Run COMMAND with ARGS.\n")) (define (run-guix-command command . args) "Run COMMAND with the given ARGS. Report an error when COMMAND is not found." + (define (command-hint guess commands) + (define command-names + (map (lambda (command) + (match (command-name command) + ((head tail ...) head))) + commands)) + (string-closest (symbol->string guess) command-names #:threshold 3)) + (define module (catch 'misc-error (lambda () @@ -2139,9 +2147,12 @@ found." (load file) (resolve-interface `(guix extensions ,command))))) (lambda _ - (format (current-error-port) - (G_ "guix: ~a: command not found~%") command) - (show-guix-usage)))))) + (let ((hint (command-hint command (commands)))) + (when hint + (display-hint (format #f (G_ "Do you mean @code{~a}?") hint))) + (format (current-error-port) + (G_ "guix: ~a: command not found~%") command) + (show-guix-usage))))))) (let ((command-main (module-ref module (symbol-append 'guix- command)))) -- 2.29.2