GNU bug report logs - #66358
Some options are really subcommands + ignore arguments

Previous Next

Package: guix;

Reported by: "Perry, Daniel J" <dperry45 <at> gatech.edu>

Date: Thu, 5 Oct 2023 05:14:03 UTC

Severity: normal

To reply to this bug, email your comments to 66358 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Thu, 05 Oct 2023 05:14:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Perry, Daniel J" <dperry45 <at> gatech.edu>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Thu, 05 Oct 2023 05:14:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Perry, Daniel J" <dperry45 <at> gatech.edu>
To: "bug-guix <at> gnu.org" <bug-guix <at> gnu.org>
Subject: Can't import package using archive command
Date: Thu, 5 Oct 2023 03:35:20 +0000
[Message part 1 (text/plain, inline)]
  1.  guix archive --export hello > hello.nar
  2.  guix archive --import --authorize hello < hello.nar

This gives a fatal error on my machine (Debian on wsl) and was reproduced on Guix proper my a member of the IRC chat.
[Message part 2 (text/html, inline)]

Information forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Mon, 09 Oct 2023 12:27:02 GMT) Full text and rfc822 format available.

Message #8 received at 66358 <at> debbugs.gnu.org (full text, mbox):

From: Tobias Geerinckx-Rice <me <at> tobias.gr>
To: "Perry, Daniel J" <dperry45 <at> gatech.edu>
Cc: control <at> debbugs.gnu.org, 66358 <at> debbugs.gnu.org
Subject: Re: bug#66358: Can't import package using archive command
Date: Mon, 09 Oct 2023 14:25:51 +0200
retitle 66358 ‘guix archive --{authorize,import,…}’ are really 
subcommands + ignore some arguments
thanks

Hi Daniel,

The error is correct, so I sure hope it's reproducible!

Later options cancel out previous ones, so your ‘--authorize’ action 
takes precedence over ‘--import’.  You're passing it a binary .nar 
archive as a private key (which is an s-expression).

Boom.

Instead:

  1.  guix archive --export hello > hello.nar
  2.  guix archive --authorize < export-host.private-key
  3.  guix archive --import < hello.nar

Note that you had an extra ‘hello’ in your --import command as well.  
Please note that it does nothing.  Option parsing in Guix is 
surprisingly lax.

I started thinking about a nice way to make ‘--action’ options mutually 
exclusive, but reconsidered.  I think it would violate POLA if not 
POSIX.

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 don't know if that change is still worth making here.

Kind regards,

T G-R

Sent from a Web browser.  Excuse or enjoy my brevity.




Information forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Mon, 09 Oct 2023 12:34:01 GMT) Full text and rfc822 format available.

Message #11 received at 66358 <at> debbugs.gnu.org (full text, mbox):

From: Tobias Geerinckx-Rice <me <at> tobias.gr>
To: control <at> debbugs.gnu.org, 66358 <at> debbugs.gnu.org
Subject: Re: bug#66358: Some options are really subcommands + ignore arguments
Date: Mon, 09 Oct 2023 14:32:58 +0200
retitle 66358 Some options are really subcommands + ignore arguments
thanks

Today, we learn that ‘ and ’ are non-free:

> Processing commands for control <at> debbugs.gnu.org:
>> retitle 66358 ‘guix archive --{authorize,import,…}’ are really
> Failed to set the title of 66358: Non-printable characters are not 
> allowed in bug titles.

All are bugs, bugs are all.

Kind regards,

T G-R

Sent from a Web browser.  Excuse or enjoy my brevity.




Changed bug title to 'Some options are really subcommands + ignore arguments' from 'Can't import package using archive command' Request was from Tobias Geerinckx-Rice <me <at> tobias.gr> to control <at> debbugs.gnu.org. (Mon, 09 Oct 2023 12:34:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Mon, 09 Oct 2023 16:54:02 GMT) Full text and rfc822 format available.

Message #16 received at 66358 <at> debbugs.gnu.org (full text, mbox):

From: "Perry, Daniel J" <dperry45 <at> gatech.edu>
To: "me <at> tobias.gr" <me <at> tobias.gr>
Cc: "66358 <at> debbugs.gnu.org" <66358 <at> debbugs.gnu.org>
Subject: Now what about firmware?
Date: Mon, 9 Oct 2023 16:52:45 +0000
[Message part 1 (text/plain, inline)]
Okay, great! I didn't think that they were mutually exclusive.
However, I still have a problem. You see, the reason why I'm using "guix archive" in the first place is because I don't have the wifi drivers for my laptop and I'm trying to install it without any Internet.

I don't think that simply adding the files to the store will work in this case, so I'll probably have to copy the source code, copy gcc-toolchain, copy the lisp code that describes the firmware package, and build there.

In any case, thanks a lot.
[Message part 2 (text/html, inline)]

Information forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Thu, 12 Oct 2023 08:09:02 GMT) Full text and rfc822 format available.

Message #19 received at 66358 <at> debbugs.gnu.org (full text, mbox):

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: Tobias Geerinckx-Rice <me <at> tobias.gr>, "Perry, Daniel J"
 <dperry45 <at> gatech.edu>
Cc: control <at> debbugs.gnu.org, 66358 <at> debbugs.gnu.org
Subject: Re: bug#66358: Can't import package using archive command
Date: Thu, 12 Oct 2023 01:27:14 +0200
[Message part 1 (text/plain, inline)]
Hi,

On Mon, 09 Oct 2023 at 14:25, Tobias Geerinckx-Rice via Bug reports for GNU Guix <bug-guix <at> 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

[0001-scripts-archive-Check-compatibility-of-command-line-.patch (text/x-diff, inline)]
From 673afe0384427bc92fa47870e1dfa092e04aec0b Mon Sep 17 00:00:00 2001
Message-Id: <673afe0384427bc92fa47870e1dfa092e04aec0b.1697066456.git.zimon.toutoune <at> gmail.com>
From: Simon Tournier <zimon.toutoune <at> 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 <at> 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 <at> gnu.org>
 ;;; Copyright © 2020 Tobias Geerinckx-Rice <me <at> tobias.gr>
+;;; Copyright © 2023 Simon Tournier <zimon.toutoune <at> 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


Information forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Tue, 24 Oct 2023 14:49:02 GMT) Full text and rfc822 format available.

Message #22 received at 66358 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Simon Tournier <zimon.toutoune <at> gmail.com>
Cc: control <at> debbugs.gnu.org, Tobias Geerinckx-Rice <me <at> tobias.gr>, "Perry,
 Daniel J" <dperry45 <at> gatech.edu>, 66358 <at> debbugs.gnu.org
Subject: Re: bug#66358: Some options are really subcommands + ignore arguments
Date: Tue, 24 Oct 2023 10:48:18 -0400
Hi Simon,

Simon Tournier <zimon.toutoune <at> gmail.com> writes:

> Hi,
>
> On Mon, 09 Oct 2023 at 14:25, Tobias Geerinckx-Rice via Bug reports
> for GNU Guix <bug-guix <at> 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“.

It seems a reasonable improvement to me, but I think *all* the
incompatible errors should be accumulated and printed in one go.

-- 
Thanks,
Maxim




Information forwarded to bug-guix <at> gnu.org:
bug#66358; Package guix. (Tue, 24 Oct 2023 18:15:02 GMT) Full text and rfc822 format available.

Message #25 received at 66358 <at> debbugs.gnu.org (full text, mbox):

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Cc: control <at> debbugs.gnu.org, Tobias Geerinckx-Rice <me <at> tobias.gr>, "Perry,
 Daniel J" <dperry45 <at> gatech.edu>, 66358 <at> debbugs.gnu.org
Subject: Re: bug#66358: Some options are really subcommands + ignore arguments
Date: Tue, 24 Oct 2023 18:39:29 +0200
Hi,

On Tue, 24 Oct 2023 at 10:48, Maxim Cournoyer <maxim.cournoyer <at> gmail.com> wrote:

> It seems a reasonable improvement to me, but I think *all* the
> incompatible errors should be accumulated and printed in one go.

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix archive --import --authorize hello --export < /tmp/hello.nar
guix archive: error: the options 'import' 'export' 'authorize' are exclusive
--8<---------------cut here---------------end--------------->8---

See v2 in #66592.

  [bug#66592] [PATCH v2] scripts: archive: Check compatibility of command line options.
  Simon Tournier <zimon.toutoune <at> gmail.com>
  Tue, 24 Oct 2023 18:33:10 +0200
  id:5c26f17bbf1b4cf9872b4a782295260ce337d3fd.1698165008.git.zimon.toutoune <at> gmail.com
  https://issues.guix.gnu.org/66592
  https://issues.guix.gnu.org/msgid/5c26f17bbf1b4cf9872b4a782295260ce337d3fd.1698165008.git.zimon.toutoune <at> gmail.com
  https://yhetil.org/guix/5c26f17bbf1b4cf9872b4a782295260ce337d3fd.1698165008.git.zimon.toutoune <at> gmail.com

Cheers,
simon




This bug report was last modified 1 year and 240 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.