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 GHGEBjZPB2CRUgAA0tVLHw (envelope-from ) for ; Tue, 19 Jan 2021 21:29:26 +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 2A1UAjZPB2BGHgAAbx9fmQ (envelope-from ) for ; Tue, 19 Jan 2021 21:29:26 +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 94887940503 for ; Tue, 19 Jan 2021 21:29:25 +0000 (UTC) Received: from localhost ([::1]:49134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1yZ2-0004tn-IC for larch@yhetil.org; Tue, 19 Jan 2021 16:29:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1yYg-0004gK-LJ for guix-patches@gnu.org; Tue, 19 Jan 2021 16:29:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40397) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1yYg-0008M9-EU 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 1l1yYg-0005op-Bj for guix-patches@gnu.org; Tue, 19 Jan 2021 16:29:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45893] [PATCH v3 2/3] guix: scripts: Add hint for option typo. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 19 Jan 2021 21:29:02 +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.161109171422314 (code B ref 45893); Tue, 19 Jan 2021 21:29:02 +0000 Received: (at 45893) by debbugs.gnu.org; 19 Jan 2021 21:28:34 +0000 Received: from localhost ([127.0.0.1]:51940 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1yYD-0005nn-Ip for submit@debbugs.gnu.org; Tue, 19 Jan 2021 16:28:33 -0500 Received: from mail-wr1-f50.google.com ([209.85.221.50]:37877) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1yY9-0005nG-2A for 45893@debbugs.gnu.org; Tue, 19 Jan 2021 16:28:30 -0500 Received: by mail-wr1-f50.google.com with SMTP id v15so17486063wrx.4 for <45893@debbugs.gnu.org>; Tue, 19 Jan 2021 13:28:29 -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=B9yOI7weg3PgvZxylgSXhQT3lanNe9Wi7hAgSbLA+XA=; b=DQFZ5Mqel+4OYM2KF7bV7jvIP99jXLT92Db6igPqXuPk5miBg50Jvv1an2G51TdEqy o6AeWVYDw/R64aXVyB0obL7gXmcBCtpHPR773qFCu36W4ZKuRFsIjofjmZlUOExm1k9U sPNDkUhRVJbf6SpPn7qAR+bR1O+jVxnO0+//GwuRH1z6bsn6MUAwEcZp+b60ghn+kMKt 2fSZbta9LI/bHAga3JXr3f9eXy7FpVp5JvSzwQpzlU/Jsrv20Stob6gX4+Be1I8ev4z1 6eOHDc4LV9CIqN3fqs7mWsqsv8ucS36v6h64AZWpaKsQifpaKsEsPPPD0sl868GqvLTZ XrAw== 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=B9yOI7weg3PgvZxylgSXhQT3lanNe9Wi7hAgSbLA+XA=; b=MQ2XzQ8p+CJKovV53AXODsaASM+VfXnoYG0mtA0IAD8RB5IxvgRPUs2gaM4K6c7uN+ rMxBzkqp1U+gJIGMe7zmbo7PZ6pj0jMWvCobrZ3mDiotSi0xXTSw5JNGYcOq4y3RmlcH MthsYlkBzuKJhivSH30hIFx0sWrm34yGEh8wvl9oOLkevBVeHvyG2fUStzRvaPWLeRju wfl66ttlzpsyuP0hEnNbUVpyXddPNK9JuavKZw121nio/Xyf+s00HHLzmi3c3wyde7Oi K2ckV8kfqkrTCKDZMYQaynanfPTMpXt2jPchmi0CCiHQEKZVcE3qEm1N95TK7H497aeY raxw== X-Gm-Message-State: AOAM531ulfIOUAVWj+tzzzDW2bBQdkZJrRiuIahsC3I/m1BsVheT92xH WdTjK/eLff3QPrQH2+5903k0Q4gcCbg= X-Google-Smtp-Source: ABdhPJzu7fld2IXcoH9Qz/bUDSSRb5RBnvlvOTrjjY5mz3mbMtsQDmXy+OjvUy5VvTv3haqHPkc1kA== X-Received: by 2002:a5d:674b:: with SMTP id l11mr6365680wrw.247.1611091702414; Tue, 19 Jan 2021 13:28:22 -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.21 (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:09 +0100 Message-Id: <20210119212810.20681-2-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-Type: text/plain; charset=UTF-8 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: -1.25 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=DQFZ5Mqe; 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: 94887940503 X-Spam-Score: -1.25 X-Migadu-Scanner: scn0.migadu.com X-TUID: Q6iK2lylKzZ1 * guix/scripts.scm (option-hint): New procedure. (parse-command-line): Add 'option-hint'. --- guix/scripts.scm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/guix/scripts.scm b/guix/scripts.scm index 34cba35401..e997edbb6d 100644 --- a/guix/scripts.scm +++ b/guix/scripts.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2015, 2016 Alex Kost ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2021 Ricardo Wurmus +;;; Copyright © 2021 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -112,6 +113,13 @@ procedure, but both the category and synopsis are meant to be read (parsed) by doc body ...))))) +(define (option-hint guess options) + "Return the closest long-name OPTIONS from GUESS, +according to'string-distance'." + (define (options->long-names options) + (filter string? (append-map option-names options))) + (string-closest guess (options->long-names options) #:threshold 3)) + (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." @@ -149,7 +157,11 @@ parameter of 'args-fold'." ;; Actual parsing takes place here. (apply args-fold* args options (lambda (opt name arg . rest) - (leave (G_ "~A: unrecognized option~%") name)) + (let ((hint (option-hint name options))) + (when hint + (display-hint + (format #f (G_ "Do you mean @code{~a}?~%") hint))) + (leave (G_ "~A: unrecognized option~%") name))) argument-handler seeds)) -- 2.29.2