From: Simon Tournier <zimon.toutoune@gmail.com>
To: Tobias Geerinckx-Rice <me@tobias.gr>,
"Perry, Daniel J" <dperry45@gatech.edu>
Cc: control@debbugs.gnu.org, 66358@debbugs.gnu.org
Subject: bug#66358: Can't import package using archive command
Date: Thu, 12 Oct 2023 01:27:14 +0200 [thread overview]
Message-ID: <86pm1kd9kd.fsf@gmail.com> (raw)
In-Reply-To: <74541e429369739b82716cd72ee3b511@tobias.gr>
[-- Attachment #1: Type: text/plain, Size: 1079 bytes --]
Hi,
On Mon, 09 Oct 2023 at 14:25, Tobias Geerinckx-Rice via Bug reports for GNU Guix <bug-guix@gnu.org> wrote:
> I think it would be less surprising if these ‘single, mutually exclusive
> actions’ should always be (sub)subcommands, e.g., ‘guix archive import’,
> ‘guix archive authorize’, …
I am proposing to error for ambiguous cases as,
$ ./pre-inst-env guix archive --import --authorize hello < /tmp/hello.nar
guix archive: error: ambiguous options: "authorize" with "import"
See attached patch. WDYT?
Please note that it errors when at least 2 options are ambiguous. So if
there is 3, you get the “two first ones“.
--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix archive --import --export --authorize hello < /tmp/hello.nar
guix archive: error: ambiguous options: "export" with "import"
--8<---------------cut here---------------end--------------->8---
Well, if the idea is fine, then maybe it could be worth to add one or
two sentences in the manual.
Cheers,
simon
[-- Attachment #2: fixes.patch --]
[-- Type: text/x-diff, Size: 3366 bytes --]
From 673afe0384427bc92fa47870e1dfa092e04aec0b Mon Sep 17 00:00:00 2001
Message-Id: <673afe0384427bc92fa47870e1dfa092e04aec0b.1697066456.git.zimon.toutoune@gmail.com>
From: Simon Tournier <zimon.toutoune@gmail.com>
Date: Thu, 12 Oct 2023 01:16:53 +0200
Subject: [PATCH] scripts: archive: Check compatibility of command line
options.
Fixes <https://issues.guix.gnu.org/66358>.
Reported by Perry, Daniel J <dperry45@gatech.edu>.
* guix/scripts/archive.scm (compatible-option): New procedure.
(%options): Use it.
---
guix/scripts/archive.scm | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm
index e32f22ec99..65932ae152 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 <ludo@gnu.org>
;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -115,6 +116,18 @@ (define %key-generation-parameters
"(genkey (ecdsa (curve Ed25519) (flags rfc6979)))"
"(genkey (rsa (nbits 4:4096)))"))
+(define (compatible-option action result other-actions)
+ "Return the RESULT if ACTION is compatible with the list of OTHER-ACTIONS."
+ (let ((other-action (fold (lambda (other answer)
+ (if (assoc-ref result (string->symbol other))
+ other
+ answer))
+ #f
+ other-actions)))
+ (if other-action
+ (leave (G_ "ambiguous options: ~s with ~s~%") action other-action)
+ (alist-cons (string->symbol action) #t result))))
+
(define %options
;; Specifications of the command-line options.
(cons* (option '(#\h "help") #f #f
@@ -126,13 +139,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 "export" result (list "import" "authorize"))))
(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 "import" result (list "export" "authorize"))))
(option '("missing") #f #f
(lambda (opt name arg result)
(alist-cons 'missing #t result)))
@@ -158,7 +171,7 @@ (define %options
(error-string err))))))
(option '("authorize") #f #f
(lambda (opt name arg result)
- (alist-cons 'authorize #t result)))
+ (compatible-option "authorize" result (list "import" "export"))))
(option '(#\S "source") #f #f
(lambda (opt name arg result)
base-commit: 0024ef320eed89468369ece3df05064a2afaabd1
--
2.38.1
next prev parent reply other threads:[~2023-10-12 8:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-05 3:35 bug#66358: Can't import package using archive command Perry, Daniel J
2023-10-09 12:25 ` Tobias Geerinckx-Rice via Bug reports for GNU Guix
2023-10-11 23:27 ` Simon Tournier [this message]
2023-10-24 14:48 ` bug#66358: Some options are really subcommands + ignore arguments Maxim Cournoyer
2023-10-24 16:39 ` Simon Tournier
2023-10-09 12:32 ` Tobias Geerinckx-Rice via Bug reports for GNU Guix
2023-10-09 16:52 ` bug#66358: Now what about firmware? Perry, Daniel J
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86pm1kd9kd.fsf@gmail.com \
--to=zimon.toutoune@gmail.com \
--cc=66358@debbugs.gnu.org \
--cc=control@debbugs.gnu.org \
--cc=dperry45@gatech.edu \
--cc=me@tobias.gr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).