From patchwork Thu Nov 30 10:46:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 57151 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 AE0E827BBEA; Thu, 30 Nov 2023 10:47:29 +0000 (GMT) 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 D4BB227BBE2 for ; Thu, 30 Nov 2023 10:47:28 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8eZP-0000DU-UM; Thu, 30 Nov 2023 05:46:59 -0500 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 1r8eZN-0000By-OS for guix-patches@gnu.org; Thu, 30 Nov 2023 05:46:58 -0500 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 1r8eZM-0006bV-PC; Thu, 30 Nov 2023 05:46:56 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8eZS-0004DB-5T; Thu, 30 Nov 2023 05:47:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#66592] [PATCH v3] scripts: archive: Check compatibility of command line options. References: In-Reply-To: Resent-From: Simon Tournier Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 30 Nov 2023 10:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66592 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66592@debbugs.gnu.org Cc: Simon Tournier , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 66592-submit@debbugs.gnu.org id=B66592.170134119516147 (code B ref 66592); Thu, 30 Nov 2023 10:47:02 +0000 Received: (at 66592) by debbugs.gnu.org; 30 Nov 2023 10:46:35 +0000 Received: from localhost ([127.0.0.1]:52416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8eZ1-0004CN-4n for submit@debbugs.gnu.org; Thu, 30 Nov 2023 05:46:35 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:39295) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8eYy-0004C8-HD for 66592@debbugs.gnu.org; Thu, 30 Nov 2023 05:46:33 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40b4ff0f254so805255e9.1 for <66592@debbugs.gnu.org>; Thu, 30 Nov 2023 02:46:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701341178; x=1701945978; darn=debbugs.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=IamyVjjN+6839Sy++oozXEYY2aXcZnw4TPp2FYwBqAU=; b=dHFHsA+O1SgNxBlssoM4lzXex9NZyaX9OVZlf6y3j2SAL7SUsqLcWFQKn3VXeeF5hW 0cahodOklQmFuYUlCnubcO2sWiPcViaoS9kcp+DdPgj5J6Nr5OLGbVWNgxiIFVamngNI mqJ/huQIiYcL0XZHYvPVGWjNVbfkznGEZwsC2yCzzE0mTV1+h5/alUjOB4ND/SN+/Ck2 dKLly5LhLB3O4QvXZnMEtgvoqZTNGGoZw7txQppjUkIaZh2UXyIR8KWoh/U/x/Dt/wC8 02AgIzudF698FZy1zzV2EjJ3I7iLzfpPBCdi6ZurM41Sqt8LqdW1wRorMgelbptmJOYp Slrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701341178; x=1701945978; 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=IamyVjjN+6839Sy++oozXEYY2aXcZnw4TPp2FYwBqAU=; b=vxlyjUdRJO/9wlk6MAasdV5Qg4dmxtGf2aWCsUFwzkYU7gGYaKA87LxpggDZKQg2zx C83Suza0de9x6TxbbdJL7IelgPm+00Uo+XfIDiMPQxunWB0qNUfaPnTcgny4HDNw1DQG /C0/qv9iZkf13GPu+0iIx91++TU01BktV06C+0dm7Sz2L6gvpIse3LEj7hYNjrhKLAOd zqGz3pSvANt7OkeKCN82AxHONb7NH/4Ua+bsrDB3HOUo+m7UJ1F+nOA6iLa5tIU4joLT +M1l5P4oZqd+PvrxrASjhC4QPj1O8MiD/8+U8iHkxith3k4Hus5R9Y0JlC/hK8TVfZSD pEuQ== X-Gm-Message-State: AOJu0Yx7MXEZJO85EPr3ZVfWMMyn0RAYJ2m7G1xuCuMwEPANSO/qBtdJ 4gg+FH2ALP8f3jc1eQiNEC88+vm5EQI= X-Google-Smtp-Source: AGHT+IEUWcbwgrHHXq5ttLQCToUPe6XWNLA7UK522SVt3Snq+LQGcTezzhzYSUlekxfGyb7gqObpYA== X-Received: by 2002:a05:600c:1c97:b0:3fe:d637:7b25 with SMTP id k23-20020a05600c1c9700b003fed6377b25mr983250wms.0.1701341178138; Thu, 30 Nov 2023 02:46:18 -0800 (PST) Received: from lili.univ-paris-diderot.fr (roam-nat-fw-prg-194-254-61-45.net.univ-paris-diderot.fr. [194.254.61.45]) by smtp.gmail.com with ESMTPSA id p36-20020a05600c1da400b0040b478da760sm1522557wms.48.2023.11.30.02.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:46:17 -0800 (PST) From: Simon Tournier Date: Thu, 30 Nov 2023 11:46:13 +0100 Message-ID: <9f5c22f6fe1f4feba5d3561cef011b0c3f55df06.1701340510.git.zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.41.0 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Fixes . Reported by Perry, Daniel J . * guix/scripts/archive.scm (guix-archive)[compatible-option]: New procedure. and use it. * tests/guix-archive.sh: Test it. --- guix/scripts/archive.scm | 18 +++++++++++++++++- tests/guix-archive.sh | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) base-commit: cd46757c1a0f886848fbb6828c028dd2a2532767 diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm index 2b5a55a23f..b9cf78f981 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. ;;; @@ -375,8 +376,23 @@ (define-command (guix-archive . args) (loop (read-line port) (cons line result))))) + (define* (compatible-option options #:key actions) + "Return the OPTIONS if it is compatible with the list of ACTIONS." + (let ((some-actions (filter (lambda (action) + (assoc-ref options action)) + actions))) + (match some-actions + ((action) + options) + ((action other-actions ...) + (leave (G_ "the options ~{'~s' ~}are exclusive~%") some-actions)) + (_ + options)))) + (with-error-handling - (let ((opts (parse-command-line args %options (list %default-options)))) + (let* ((opts (parse-command-line args %options (list %default-options))) + (opts (compatible-option opts + #:actions (list 'authorize 'export 'import)))) (parameterize ((%graft? (assoc-ref opts 'graft?))) (cond ((assoc-ref opts 'generate-key) => diff --git a/tests/guix-archive.sh b/tests/guix-archive.sh index 0866b5a4d8..08c07684ad 100644 --- a/tests/guix-archive.sh +++ b/tests/guix-archive.sh @@ -79,4 +79,9 @@ guix archive -t < "$archive" | grep "^r /share/guile.*/boot-9\.scm" echo foo | guix archive --authorize && false +# Check incompatible command-line options +guix archive --authorize --export --import && false +guix archive --export guile-bootstrap --authorize > "$archive" && false +guix archive --authorize --import < "$archive" && false + exit 0