GNU bug report logs - #47464
[PATCH 0/8] scripts: Allow option hint for various subcommands.

Previous Next

Package: guix-patches;

Reported by: zimoun <zimon.toutoune <at> gmail.com>

Date: Mon, 29 Mar 2021 10:17:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47464 in the body.
You can then email your comments to 47464 AT debbugs.gnu.org in the normal way.

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

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


Report forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to zimoun <zimon.toutoune <at> gmail.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Mon, 29 Mar 2021 10:17:02 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: guix-patches <at> gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 0/8] scripts: Allow option hint for various subcommands.
Date: Mon, 29 Mar 2021 12:16:38 +0200
Hi,

The patch set replaces all the 'args-fold*' by 'parse-command-line'.  Doing
so, all the option typos are hinted.

It could be only one commit (squashing) but it appeared me easier in case
something is wrong; I expect nothing! :-)

I have checked trying various combinations.  Note that
"tests/guix-describe.sh" is SKIP because the test does not work when using
worktree.

Well, a double-check is really welcome. :-)


All the remaining subcommands---authenticate, container, git, import, offload
and substitute---needs a rewriting of how they parse the command line
arguments.

Cheers,
simon



zimoun (8):
  scripts: describe: Replace 'args-fold*' by 'parse-command-line'.
  scripts: discover: Replace 'args-fold*' by 'parse-command-line'.
  scripts: download: Replace 'args-fold*' by 'parse-command-line'.
  scripts: edit: Replace 'args-fold*' by 'parse-command-line'.
  scripts: publish: Replace 'args-fold*' by 'parse-command-line'.
  scripts: repl: Replace 'args-fold*' by 'parse-command-line'.
  scripts: search: Replace 'args-fold*' by 'parse-command-line'.
  scripts: show: Replace 'args-fold*' by 'parse-command-line'.

 guix/scripts/describe.scm | 10 ++++------
 guix/scripts/discover.scm | 12 ++++++------
 guix/scripts/download.scm | 17 ++++++++---------
 guix/scripts/edit.scm     | 10 ++++------
 guix/scripts/publish.scm  | 12 ++++++------
 guix/scripts/repl.scm     | 11 +++++------
 guix/scripts/search.scm   |  9 ++++-----
 guix/scripts/show.scm     | 10 ++++------
 8 files changed, 41 insertions(+), 50 deletions(-)


base-commit: 6e7ba45357078b31a369b23f8a9f38302dfcbb10
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:02 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 1/8] scripts: describe: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:17:59 +0200
* guix/scripts/describe.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/describe.scm | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/guix/scripts/describe.scm b/guix/scripts/describe.scm
index be2279d254..b5f6249176 100644
--- a/guix/scripts/describe.scm
+++ b/guix/scripts/describe.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2018 Oleg Pykhalov <go.wigust <at> gmail.com>
 ;;; Copyright © 2020 Ekaitz Zarraga <ekaitz <at> elenq.tech>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -286,12 +287,9 @@ text.  The hyperlink links to a web view of COMMIT, when available."
 
 (define-command (guix-describe . args)
   (synopsis "describe the channel revisions currently used")
-  (let* ((opts    (args-fold* args %options
-                              (lambda (opt name arg result)
-                                (leave (G_ "~A: unrecognized option~%")
-                                       name))
-                              cons
-                              %default-options))
+  (let* ((opts    (parse-command-line args %options (list %default-options)
+                              #:build-options? #f
+                              #:argument-handler cons))
          (format  (assq-ref opts 'format))
          (profile (or (assq-ref opts 'profile) (current-profile))))
     (with-error-handling
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:03 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 3/8] scripts: download: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:01 +0200
* guix/scripts/download.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/download.scm | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/guix/scripts/download.scm b/guix/scripts/download.scm
index ce8dd8b02c..5a91390358 100644
--- a/guix/scripts/download.scm
+++ b/guix/scripts/download.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013, 2015, 2016, 2017, 2020 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -162,15 +163,13 @@ and 'base16' ('hex' and 'hexadecimal' can be used as well).\n"))
 
   (define (parse-options)
     ;; Return the alist of option values.
-    (args-fold* args %options
-                (lambda (opt name arg result)
-                  (leave (G_ "~A: unrecognized option~%") name))
-                (lambda (arg result)
-                  (when (assq 'argument result)
-                    (leave (G_ "~A: extraneous argument~%") arg))
-
-                  (alist-cons 'argument arg result))
-                %default-options))
+    (parse-command-line args %options (list %default-options)
+                        #:build-options? #f
+                        #:argument-handler
+                        (lambda (arg result)
+                          (when (assq 'argument result)
+                            (leave (G_ "~A: extraneous argument~%") arg))
+                          (alist-cons 'argument arg result))))
 
   (with-error-handling
     (let* ((opts  (parse-options))
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:03 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 4/8] scripts: edit: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:02 +0200
* guix/scripts/edit.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/edit.scm | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm
index 49c9d945b6..b4c0507591 100644
--- a/guix/scripts/edit.scm
+++ b/guix/scripts/edit.scm
@@ -1,7 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015, 2016, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2015 Mathieu Lirzin <mthl <at> gnu.org>
-;;; Copyright © 2020 Simon Tournier <zimon.toutoune <at> gmail.com>
+;;; Copyright © 2020, 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -84,11 +84,9 @@ line."
 
   (define (parse-arguments)
     ;; Return the list of package names.
-    (args-fold* args %options
-                (lambda (opt name arg result)
-                  (leave (G_ "~A: unrecognized option~%") name))
-                cons
-                '()))
+    (parse-command-line args %options (list (list))
+                #:build-options? #f
+                #:argument-handler cons))
 
   (with-error-handling
     (let* ((specs     (reverse (parse-arguments)))
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:03 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 2/8] scripts: discover: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:00 +0200
* guix/scripts/discover.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/discover.scm | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/guix/scripts/discover.scm b/guix/scripts/discover.scm
index 6aade81ed1..be1eaa6e95 100644
--- a/guix/scripts/discover.scm
+++ b/guix/scripts/discover.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2020 Mathieu Othacehe <othacehe <at> gnu.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -127,12 +128,11 @@ to synchronize with the writer."
   (synopsis "discover Guix related services using Avahi")
 
   (with-error-handling
-    (let* ((opts (args-fold* args %options
-                             (lambda (opt name arg result)
-                               (leave (G_ "~A: unrecognized option~%") name))
-                             (lambda (arg result)
-                               (leave (G_ "~A: extraneous argument~%") arg))
-                             %default-options))
+    (let* ((opts (parse-command-line args %options (list %default-options)
+                                     #:build-options? #f
+                                     #:argument-handler
+                                     (lambda (arg result)
+                                       (leave (G_ "~A: extraneous argument~%") arg))))
            (cache (assoc-ref opts 'cache))
            (publish-file (publish-file cache)))
       (parameterize ((%publish-file publish-file))
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:04 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 5/8] scripts: publish: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:03 +0200
* guix/scripts/publish.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/publish.scm | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index fa85088ed0..39bb224cad 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2020 by Amar M. Singh <nly <at> disroot.org>
 ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1117,12 +1118,11 @@ methods, return the applicable compression."
   (synopsis "publish build results over HTTP")
 
   (with-error-handling
-    (let* ((opts    (args-fold* args %options
-                                (lambda (opt name arg result)
-                                  (leave (G_ "~A: unrecognized option~%") name))
-                                (lambda (arg result)
-                                  (leave (G_ "~A: extraneous argument~%") arg))
-                                %default-options))
+    (let* ((opts    (parse-command-line args %options (list %default-options)
+                                        #:build-options? #f
+                                        #:argument-handler
+                                        (lambda (arg result)
+                                          (leave (G_ "~A: extraneous argument~%") arg))))
            (advertise?  (assoc-ref opts 'advertise?))
            (user        (assoc-ref opts 'user))
            (port        (assoc-ref opts 'port))
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:04 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 6/8] scripts: repl: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:04 +0200
* guix/scripts/repl.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/repl.scm | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm
index 9f20803efc..50d18c7760 100644
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
-;;; Copyright © 2020 Simon Tournier <zimon.toutoune <at> gmail.com>
+;;; Copyright © 2020, 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen <at> fastmail.net>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -143,14 +143,13 @@ call THUNK."
   (synopsis "read-eval-print loop (REPL) for interactive programming")
 
   (define opts
-    (args-fold* args %options
-                (lambda (opt name arg result)
-                  (leave (G_ "~A: unrecognized option~%") name))
+    (parse-command-line args %options (list %default-options)
+                #:build-options? #f
+                #:argument-handler
                 (lambda (arg result)
                   (append `((script . ,arg)
                             (ignore-dot-guile? . #t))
-                          result))
-                %default-options))
+                          result))))
 
   (define user-config
     (and=> (getenv "HOME")
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:05 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 7/8] scripts: search: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:05 +0200
* guix/scripts/search.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/search.scm | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/guix/scripts/search.scm b/guix/scripts/search.scm
index 0c9e6af07b..27b9da5278 100644
--- a/guix/scripts/search.scm
+++ b/guix/scripts/search.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -66,11 +67,9 @@ This is an alias for 'guix package -s'.\n"))
           result))
 
   (define opts
-    (args-fold* args %options
-                (lambda (opt name arg . rest)
-                  (leave (G_ "~A: unrecognized option~%") name))
-                handle-argument
-                '()))
+    (parse-command-line args %options (list (list))
+                        #:build-options? #f
+                        #:argument-handler handle-argument))
 
   (unless (assoc-ref opts 'query)
     (leave (G_ "missing arguments: no regular expressions to search for~%")))
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47464; Package guix-patches. (Mon, 29 Mar 2021 10:19:05 GMT) Full text and rfc822 format available.

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

From: zimoun <zimon.toutoune <at> gmail.com>
To: 47464 <at> debbugs.gnu.org
Cc: zimoun <zimon.toutoune <at> gmail.com>
Subject: [PATCH 8/8] scripts: show: Replace 'args-fold*' by
 'parse-command-line'.
Date: Mon, 29 Mar 2021 12:18:06 +0200
* guix/scripts/show.scm (define-command): Replace 'args-fold*' by
'parse-command-line'.
---
 guix/scripts/show.scm | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/guix/scripts/show.scm b/guix/scripts/show.scm
index 535d03c1a6..c747eedd21 100644
--- a/guix/scripts/show.scm
+++ b/guix/scripts/show.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2019 Simon Tournier <zimon.toutoune <at> gmail.com>
+;;; Copyright © 2019, 2021 Simon Tournier <zimon.toutoune <at> gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -66,11 +66,9 @@ This is an alias for 'guix package --show='.\n"))
           result))
 
   (define opts
-    (args-fold* args %options
-                (lambda (opt name arg . rest)
-                  (leave (G_ "~A: unrecognized option~%") name))
-                handle-argument
-                '()))
+    (parse-command-line args %options (list (list))
+                        #:build-options? #f
+                        #:argument-handler handle-argument))
 
   (unless (assoc-ref opts 'query)
     (leave (G_ "missing arguments: no package to show~%")))
-- 
2.30.1





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Thu, 01 Apr 2021 12:58:01 GMT) Full text and rfc822 format available.

Notification sent to zimoun <zimon.toutoune <at> gmail.com>:
bug acknowledged by developer. (Thu, 01 Apr 2021 12:58:01 GMT) Full text and rfc822 format available.

Message #34 received at 47464-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: zimoun <zimon.toutoune <at> gmail.com>
Cc: 47464-done <at> debbugs.gnu.org
Subject: Re: bug#47464: [PATCH 0/8] scripts: Allow option hint for various
 subcommands.
Date: Thu, 01 Apr 2021 14:57:27 +0200
Hi!

zimoun <zimon.toutoune <at> gmail.com> skribis:

> The patch set replaces all the 'args-fold*' by 'parse-command-line'.  Doing
> so, all the option typos are hinted.

Yay!

> It could be only one commit (squashing) but it appeared me easier in case
> something is wrong; I expect nothing! :-)
>
> I have checked trying various combinations.  Note that
> "tests/guix-describe.sh" is SKIP because the test does not work when using
> worktree.
>
> Well, a double-check is really welcome. :-)

All the tests pass, LGTM!

> All the remaining subcommands---authenticate, container, git, import, offload
> and substitute---needs a rewriting of how they parse the command line
> arguments.

Future work.

Applied, thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 30 Apr 2021 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 360 days ago.

Previous Next


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