From patchwork Tue Oct 17 13:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 54934 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 7A3F927BBE9; Tue, 17 Oct 2023 14:30:05 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7779B27BBE2 for ; Tue, 17 Oct 2023 14:30:01 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsk8l-0001Ba-3x; Tue, 17 Oct 2023 09:29:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qsk8f-0001Ai-Ri for guix-patches@gnu.org; Tue, 17 Oct 2023 09:29:42 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsk8f-0001F2-AH for guix-patches@gnu.org; Tue, 17 Oct 2023 09:29:37 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qsk94-0000GW-CG for guix-patches@gnu.org; Tue, 17 Oct 2023 09:30:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66592] [PATCH] scripts: archive: Check compatibility of command line options. Resent-From: Simon Tournier Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 17 Oct 2023 13:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66592 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66592@debbugs.gnu.org Cc: Simon Tournier X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.1697549397981 (code B ref -1); Tue, 17 Oct 2023 13:30:02 +0000 Received: (at submit) by debbugs.gnu.org; 17 Oct 2023 13:29:57 +0000 Received: from localhost ([127.0.0.1]:58883 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsk8z-0000Fk-4y for submit@debbugs.gnu.org; Tue, 17 Oct 2023 09:29:57 -0400 Received: from lists.gnu.org ([2001:470:142::17]:46918) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qsk8w-0000FW-Sy for submit@debbugs.gnu.org; Tue, 17 Oct 2023 09:29:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qsk8N-00019H-0t for guix-patches@gnu.org; Tue, 17 Oct 2023 09:29:19 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsk8K-0001Cs-82 for guix-patches@gnu.org; Tue, 17 Oct 2023 09:29:18 -0400 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-507a3af69d8so1107960e87.0 for ; Tue, 17 Oct 2023 06:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697549353; x=1698154153; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VuGaQVHTdZ3FK/nngsVRK43EdxfhroYPoQTb94Yq+fQ=; b=NvD7BRjrqlSm8GqDvV3ZEobgL0g9yvaV3VaiFsdcBh83da/5ZG1Y+9vs7CJjTF83lD 5bmEplO79btsU8QME4U9692IAsCLnQa/Fm+CTiIZovwUq7obORWORll5j572wzZbf8M0 Y9lyUPtJwSjHrHG3USX3zbaMDWJA3w4lqRUZyfnAEO+cY1JlratY5z5E2mXrOc0TihKP rxSCm7R0ZAKZmU1iITQUs0eFaUIvuVMQ2ET79qjtAY5kSCtsUXBqayulKS0mR0hXNjaH 31vXEWiCnwenp+ck1KCOMIXeell8D+9Jjdz7N0XMqOFks2UIQwmKqYoTMtB8cqFap1mt Os3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697549353; x=1698154153; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VuGaQVHTdZ3FK/nngsVRK43EdxfhroYPoQTb94Yq+fQ=; b=Lqt2xr7FIJOMgvHo8ZVmoMR5QEL67hTmk0+ur+OdzDncbyC46BfqQljZjW6iqSB+AP pUkk6s/BqSPguR8u73u0TgaOr3l5AgxvTGnj8RwbdoOWpkXHyCO9uUlRYJn7kqnAvDVG mwIDk4xc+X0woI4kMPrzZNhJU/GfCfA/yBhGRPFTuLjY46qrfA6UHJKpKLZTZaNzkmmc 2a6TpdNmuVj+ynPF2KBehTSeYwFR2qMYoURki1eJn4E36Y7HRnwI0tI2Yo1pB90zk2da LhNhU0AqJnJz6zG8RXAZ/yHj3oagoDKh5YMnTFVs5JmgRCHuBpOspILMYPQd4P0Dj5GO v5Rw== X-Gm-Message-State: AOJu0YzuNi/U4Jsvs4O4uYiqOSFkZhWsCxaWzjEuDqcgp339TNZcG+If 6wVDtYU7Mxr9kXHFmzy1mE9Gmu7Z0Ko= X-Google-Smtp-Source: AGHT+IEIry/CRfc0MhNCXcf+3KV6VW8khDs6eYLBXZYnhObVlmMOHbUxvVisltXLbSyjLZ1RZHybvg== X-Received: by 2002:a05:6512:b87:b0:507:9854:3b96 with SMTP id b7-20020a0565120b8700b0050798543b96mr1797528lfv.1.1697549352933; Tue, 17 Oct 2023 06:29:12 -0700 (PDT) Received: from localhost.localdomain ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id k2-20020a5d4282000000b0032daf848f68sm1685771wrq.59.2023.10.17.06.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 06:29:12 -0700 (PDT) From: Simon Tournier Date: Tue, 17 Oct 2023 15:28:56 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=zimon.toutoune@gmail.com; helo=mail-lf1-x12f.google.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, FREEMAIL_FROM=0.001, 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: 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Fixes . Reported by Perry, Daniel J . * guix/scripts/archive.scm (compatible-option): New procedure. (%options): Use it. --- guix/scripts/archive.scm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) base-commit: dcc5c34504c94732c135a85fb4db40ca9796270e diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm index 2b5a55a23f..a1b2b73a0f 100644 --- a/guix/scripts/archive.scm +++ b/guix/scripts/archive.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2020 Tobias Geerinckx-Rice +;;; Copyright © 2023 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -115,6 +116,22 @@ (define %key-generation-parameters "(genkey (ecdsa (curve Ed25519) (flags rfc6979)))" "(genkey (rsa (nbits 4:4096)))")) +(define* (compatible-option result + #:optional + (actions (list 'authorize 'export 'import))) + "Return the RESULT if it is compatible with the list of ACTIONS." + (let ((some-actions (fold (lambda (action answers) + (if (assoc-ref result action) + (cons action answers) + answers)) + '() + actions))) + (match some-actions + ((action) + result) + ((action other-action _ ...) + (leave (G_ "ambiguous options: ~s with ~s~%") action other-action))))) + (define %options ;; Specifications of the command-line options. (cons* (option '(#\h "help") #f #f @@ -126,13 +143,13 @@ (define %options (show-version-and-exit "guix archive"))) (option '("export") #f #f (lambda (opt name arg result) - (alist-cons 'export #t result))) + (compatible-option (alist-cons 'export #t result)))) (option '(#\r "recursive") #f #f (lambda (opt name arg result) (alist-cons 'export-recursive? #t result))) (option '("import") #f #f (lambda (opt name arg result) - (alist-cons 'import #t result))) + (compatible-option (alist-cons 'import #t result)))) (option '("missing") #f #f (lambda (opt name arg result) (alist-cons 'missing #t result))) @@ -158,7 +175,7 @@ (define %options (error-string err)))))) (option '("authorize") #f #f (lambda (opt name arg result) - (alist-cons 'authorize #t result))) + (compatible-option (alist-cons 'authorize #t result)))) (option '(#\S "source") #f #f (lambda (opt name arg result)