From patchwork Wed Sep 1 09:57:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 32485 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 500D527BBE3; Wed, 1 Sep 2021 10:59:10 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 123F627BBE1 for ; Wed, 1 Sep 2021 10:59:10 +0100 (BST) Received: from localhost ([::1]:50044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLN1R-0007O1-4T for patchwork@mira.cbaines.net; Wed, 01 Sep 2021 05:59:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLN1K-0007Na-I6 for guix-patches@gnu.org; Wed, 01 Sep 2021 05:59:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mLN1K-0006l0-AE for guix-patches@gnu.org; Wed, 01 Sep 2021 05:59:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mLN1K-0007DI-9f for guix-patches@gnu.org; Wed, 01 Sep 2021 05:59:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50314] [PATCH 2/2] system: Add hint for action typo. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 01 Sep 2021 09:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50314 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50314@debbugs.gnu.org Cc: zimoun Received: via spool by 50314-submit@debbugs.gnu.org id=B50314.163049028827635 (code B ref 50314); Wed, 01 Sep 2021 09:59:02 +0000 Received: (at 50314) by debbugs.gnu.org; 1 Sep 2021 09:58:08 +0000 Received: from localhost ([127.0.0.1]:36386 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mLN0S-0007Bf-Ae for submit@debbugs.gnu.org; Wed, 01 Sep 2021 05:58:08 -0400 Received: from mail-wm1-f50.google.com ([209.85.128.50]:45717) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mLN0Q-0007BA-AZ for 50314@debbugs.gnu.org; Wed, 01 Sep 2021 05:58:06 -0400 Received: by mail-wm1-f50.google.com with SMTP id j17-20020a05600c1c1100b002e754875260so1490125wms.4 for <50314@debbugs.gnu.org>; Wed, 01 Sep 2021 02:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8glmS5tCI43DzUtm0jB32OQqUaiGRoXg/FRzZEX/T1Q=; b=eIWv+sBeLVy6c01baO/8XM/ls5GCUPKSI2J4lgOIMGJre0I7iCvwBJjtuMwHeeuq9L s2H8GTMWEjMCQMJAr0Wfk621xDkPxx6mhMISQQbJj4X1TQ7tkYdno4oFry8NAauTybxV 0fRZo2RumClEEXCGkqcaNj6H09GTd/BJyoeIrmCh/b86Sih413oGohIM98nT3Qd7TKBC I6pNr1MwcEJ+W6HJd8Z5LrhGtyre7fpW7nv3PzzRwMsK+6iySckMfLYwZXH9dgPXPYoX jaTgoy50YjcaPP42zLDoaukcN1IP/9SGrzoxXher21ODR868pMJRDHvyULtAWfTDfU1E TdAg== 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=8glmS5tCI43DzUtm0jB32OQqUaiGRoXg/FRzZEX/T1Q=; b=ny8PSnDhEzkCyJhKpHapY47kWmsD6J/qsIGKVKVo4ea4zBepctkWBd/NcEgCaie6XA Bye17zuDEwaZMCWGwfVEwx25Cta6Pypqi7rzPvYZvaauVMclvrMQ9pqGevyAPbQMup/D 7BQM8C7KBPURkIUcQ9HRHTUkanXrU6H0fB4B0wYfnOVDMrKpCMVwJ2BiBjYvkUupAaS8 wxq22QhBRCaM/aCgBWda0nqXjXTrNjMyuL6lknbDgD87gWC1iVfAzpLhEH7Ko6YuhVRR zg+Of4C6ERo3RfLxnIxm9/UBTWOp4zVBwRoz8g9y3wny9/MeW0XQsFvjEWn+7Evr5Aom GqKw== X-Gm-Message-State: AOAM532xqVoN073d94t7f8LYYTF9rBgRErvW3mL0OtMx5Np+thNyKqFB LSVQ0U7hGtKnZjuHt7oL8mYvMfTe1pSmPg== X-Google-Smtp-Source: ABdhPJxGSOuJ5jsq/TUskWxqfnIikvgx8FIJI98SERCACKS4TNE6qhx/eLfjFertSsqGFWb7uQFJUw== X-Received: by 2002:a1c:730a:: with SMTP id d10mr8870148wmb.59.1630490280343; Wed, 01 Sep 2021 02:58:00 -0700 (PDT) Received: from lili.univ-paris-diderot.fr ([2a01:e0a:59b:9120:65d2:2476:f637:db1e]) by smtp.gmail.com with ESMTPSA id v5sm21772535wru.37.2021.09.01.02.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 02:58:00 -0700 (PDT) From: zimoun Date: Wed, 1 Sep 2021 11:57:56 +0200 Message-Id: <20210901095756.13752-2-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210901095756.13752-1-zimon.toutoune@gmail.com> References: <20210901095756.13752-1-zimon.toutoune@gmail.com> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/system.scm (actions): New variable. (define-command): Add hint for action typo. --- guix/scripts/system.scm | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 83bbefd3dc..65eb98e4b2 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2020 Julien Lepiller ;;; Copyright © 2020 Efraim Flashner ;;; Copyright © 2021 Brice Waegeneire +;;; Copyright © 2021 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -1152,6 +1153,13 @@ Some ACTIONS support additional ARGS.\n")) ;;; Entry point. ;;; +(define actions '("build" "container" "vm" "vm-image" "image" "disk-image" + "reconfigure" "init" + "extension-graph" "shepherd-graph" + "list-generations" "describe" + "delete-generations" "roll-back" + "switch-generation" "search" "docker-image")) + (define (process-action action args opts) "Process ACTION, a sub-command, with the arguments are listed in ARGS. ACTION must be one of the sub-commands that takes an operating system @@ -1335,17 +1343,18 @@ argument list and OPTS is the option alist." (define (parse-sub-command arg result) ;; Parse sub-command ARG and augment RESULT accordingly. - (if (assoc-ref result 'action) - (alist-cons 'argument arg result) - (let ((action (string->symbol arg))) - (case action - ((build container vm vm-image image disk-image reconfigure init - extension-graph shepherd-graph - list-generations describe - delete-generations roll-back - switch-generation search docker-image) - (alist-cons 'action action result)) - (else (leave (G_ "~a: unknown action~%") action)))))) + (cond ((assoc-ref result 'action) + (alist-cons 'argument arg result)) + ((member arg actions) + (let ((action (string->symbol arg))) + (alist-cons 'action action result))) + (else + (let ((hint (string-closest arg actions #:threshold 3))) + (report-error (G_ "~a: unknown action~%") arg) + (when hint + (display-hint + (format #f (G_ "Did you mean @code{~a}?~%") hint))) + (exit 1))))) (define (match-pair car) ;; Return a procedure that matches a pair with CAR.