[PATCH] scripts: repl: Add --interactive and --list-types flags.

  • Done
  • quality assurance status badge
Details
3 participants
  • Antero Mejr
  • Maxim Cournoyer
  • zimoun
Owner
unassigned
Submitted by
Antero Mejr
Severity
normal
A
A
Antero Mejr wrote on 2 Dec 2022 03:56
(address . guix-patches@gnu.org)(name . Antero Mejr)(address . antero@mailbox.org)
20221202025641.9318-1-antero@mailbox.org
* guix/scripts/repl.scm (guix-repl): Honor -i, --interactive flag.
(%options): Add -i/--interactive and --l/--list-types.
---
guix/scripts/repl.scm | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

Toggle diff (51 lines)
diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm
index 50d18c7760..eac3d7264e 100644
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -52,12 +52,19 @@ (define %options
(option '(#\t "type") #t #f
(lambda (opt name arg result)
(alist-cons 'type (string->symbol arg) result)))
+ (option '(#\l "list-types") #f #f
+ (lambda (opt name arg result)
+ (display (string-join '("guile" "machine") "\n" 'suffix))
+ (exit 0)))
(option '("listen") #t #f
(lambda (opt name arg result)
(alist-cons 'listen arg result)))
(option '(#\q) #f #f
(lambda (opt name arg result)
(alist-cons 'ignore-dot-guile? #t result)))
+ (option '(#\i "interactive") #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'interactive? #t result)))
(option '(#\L "load-path") #t #f
(lambda (opt name arg result)
;; XXX: Imperatively modify the search paths.
@@ -78,9 +85,15 @@ (define (show-help)
-q inhibit loading of ~/.guile"))
(newline)
(display (G_ "
+ -i, --interactive launch REPL after evaluating FILE"))
+ (newline)
+ (display (G_ "
-L, --load-path=DIR prepend DIR to the package module search path"))
(newline)
(display (G_ "
+ -l, --list-types display REPL types and exit"))
+ (newline)
+ (display (G_ "
-h, --help display this help and exit"))
(display (G_ "
-V, --version display version information and exit"))
@@ -190,7 +203,7 @@ (define script
;; file in %LOAD-PATH. Thus, pass (getcwd) instead of ".".
(load-in-vicinity (getcwd) (car script)))))
- (when (null? script)
+ (when (or (null? script) (assoc-ref opts 'interactive?))
;; Start REPL
(let ((type (assoc-ref opts 'type)))
(call-with-connection (assoc-ref opts 'listen)
--
2.38.1
A
A
Antero Mejr wrote on 2 Dec 2022 04:35
[PATCH] doc: Add new flag information to REPL section.
(address . 59754@debbugs.gnu.org)(name . Antero Mejr)(address . antero@mailbox.org)
20221202033542.1849-1-antero@mailbox.org
* doc/guix.texi (Invoking guix repl): Add new flag information for
--interactive and --list-types.
---
doc/guix.texi | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

Toggle diff (37 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 47b805dc7f..ec3cd8127c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -11992,6 +11992,14 @@ lines at the top of the script:
@code{!#}
@end example
+To make a script that launches an interactive REPL directly from the
+shell, use the @code{--interactive} flag:
+
+@example
+@code{#!/usr/bin/env -S guix repl --interactive}
+@code{!#}
+@end example
+
Without a file name argument, a Guile REPL is started, allowing for
interactive use (@pxref{Using Guix Interactively}):
@@ -12044,6 +12052,15 @@ Add @var{directory} to the front of the package module search path
This allows users to define their own packages and make them visible to
the script or REPL.
+@item --interactive
+@itemx -i
+Launch the interactive REPL after @var{FILE} is executed.
+
+@item --list-types
+@itemx -l
+Display the @var{TYPE} options for @command{guix repl --type=TYPE} and
+exit.
+
@item -q
Inhibit loading of the @file{~/.guile} file. By default, that
configuration file is loaded when spawning a @code{guile} REPL.
--
2.38.1
Z
Z
zimoun wrote on 2 Dec 2022 16:46
Re: [bug#59754] [PATCH] scripts: repl: Add --interactive and --list-types flags.
87tu2dreof.fsf@gmail.com
Hi,

Thanks, nice!

On Fri, 02 Dec 2022 at 02:56, Antero Mejr via Guix-patches via <guix-patches@gnu.org> wrote:
Toggle quote (2 lines)
> * guix/scripts/repl.scm (guix-repl): Honor -i, --interactive flag.
> (%options): Add -i/--interactive and --l/--list-types.
-^
Typo

The patch LGTM, minor three comments.

1. I would not use the shortkey -l; only the long one.
2. I would move --list-types right before -t/--type

Toggle snippet (13 lines)
--list-types display REPL types and exit
-t, --type=TYPE start a REPL of the given TYPE
--listen=ENDPOINT listen to ENDPOINT instead of standard input
-q inhibit loading of ~/.guile

-i, --interactive launch REPL after evaluating FILE

-L, --load-path=DIR prepend DIR to the package module search path

-h, --help display this help and exit
-V, --version display version information and exit

3. I would split the addition of --list-types and --interactive in two
separated commits. But for each option, I would also change the manual
with the same commit. Else, please squash this submission. :-)


Cheers,
simon
A
A
Antero Mejr wrote on 3 Dec 2022 02:09
[PATCH 1/2] scripts: repl: Add --list-types flag.
(address . 59754@debbugs.gnu.org)(name . Antero Mejr)(address . antero@mailbox.org)
20221203010937.2332-1-antero@mailbox.org
* guix/scripts/repl.scm (%options): Add --list-types.
* doc/guix.texi (Invoking guix repl): Add documentation for --list-types.
---
doc/guix.texi | 4 ++++
guix/scripts/repl.scm | 6 ++++++
2 files changed, 10 insertions(+)

Toggle diff (41 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 47b805dc7f..cf9e6f640d 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -12011,6 +12011,10 @@ of Guix.
The available options are as follows:
@table @code
+@item --list-types
+Display the @var{TYPE} options for @command{guix repl --type=TYPE} and
+exit.
+
@item --type=@var{type}
@itemx -t @var{type}
Start a REPL of the given @var{TYPE}, which can be one of the following:
diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm
index 50d18c7760..0ec62786e9 100644
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -52,6 +52,10 @@ (define %options
(option '(#\t "type") #t #f
(lambda (opt name arg result)
(alist-cons 'type (string->symbol arg) result)))
+ (option '("list-types") #f #f
+ (lambda (opt name arg result)
+ (display (string-join '("guile" "machine") "\n" 'suffix))
+ (exit 0)))
(option '("listen") #t #f
(lambda (opt name arg result)
(alist-cons 'listen arg result)))
@@ -70,6 +74,8 @@ (define (show-help)
(display (G_ "Usage: guix repl [OPTIONS...] [-- FILE ARGS...]
In the Guix execution environment, run FILE as a Guile script with
command-line arguments ARGS. If no FILE is given, start a Guile REPL.\n"))
+ (display (G_ "
+ --list-types display REPL types and exit"))
(display (G_ "
-t, --type=TYPE start a REPL of the given TYPE"))
(display (G_ "
--
2.38.1
A
A
Antero Mejr wrote on 3 Dec 2022 02:09
[PATCH 2/2] scripts: repl: Add -i, --interactive flag.
(address . 59754@debbugs.gnu.org)(name . Antero Mejr)(address . antero@mailbox.org)
20221203010937.2332-2-antero@mailbox.org
* guix/scripts/repl.scm (%options): Add -i, --interactive flag.
(guix-repl): Honor -i, --interactive flag.
* doc/guix.texi (Invoking guix repl): Add documentation for -i, --interactive.
---
doc/guix.texi | 12 ++++++++++++
guix/scripts/repl.scm | 8 +++++++-
2 files changed, 19 insertions(+), 1 deletion(-)

Toggle diff (65 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index cf9e6f640d..3391c7a66c 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -11992,6 +11992,14 @@ lines at the top of the script:
@code{!#}
@end example
+To make a script that launches an interactive REPL directly from the
+shell, use the @code{--interactive} flag:
+
+@example
+@code{#!/usr/bin/env -S guix repl --interactive}
+@code{!#}
+@end example
+
Without a file name argument, a Guile REPL is started, allowing for
interactive use (@pxref{Using Guix Interactively}):
@@ -12040,6 +12048,10 @@ Accept connections on localhost on port 37146.
Accept connections on the Unix-domain socket @file{/tmp/socket}.
@end table
+@item --interactive
+@itemx -i
+Launch the interactive REPL after @var{FILE} is executed.
+
@item --load-path=@var{directory}
@itemx -L @var{directory}
Add @var{directory} to the front of the package module search path
diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm
index 0ec62786e9..787c63d48e 100644
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -62,6 +62,9 @@ (define %options
(option '(#\q) #f #f
(lambda (opt name arg result)
(alist-cons 'ignore-dot-guile? #t result)))
+ (option '(#\i "interactive") #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'interactive? #t result)))
(option '(#\L "load-path") #t #f
(lambda (opt name arg result)
;; XXX: Imperatively modify the search paths.
@@ -84,6 +87,9 @@ (define (show-help)
-q inhibit loading of ~/.guile"))
(newline)
(display (G_ "
+ -i, --interactive launch REPL after evaluating FILE"))
+ (newline)
+ (display (G_ "
-L, --load-path=DIR prepend DIR to the package module search path"))
(newline)
(display (G_ "
@@ -196,7 +202,7 @@ (define script
;; file in %LOAD-PATH. Thus, pass (getcwd) instead of ".".
(load-in-vicinity (getcwd) (car script)))))
- (when (null? script)
+ (when (or (null? script) (assoc-ref opts 'interactive?))
;; Start REPL
(let ((type (assoc-ref opts 'type)))
(call-with-connection (assoc-ref opts 'listen)
--
2.38.1
A
A
Antero Mejr wrote on 3 Dec 2022 02:10
Re: [bug#59754] [PATCH] scripts: repl: Add --interactive and --list-types flags.
(name . zimoun)(address . zimon.toutoune@gmail.com)
87r0xhb88m.fsf@mailbox.org
zimoun <zimon.toutoune@gmail.com> writes:

Toggle quote (6 lines)
> Hi,
>
> Thanks, nice!
>
> The patch LGTM, minor three comments.

Split up the commits and made the suggested fixes. Thanks for the review!
M
M
Maxim Cournoyer wrote on 16 Jan 2023 15:03
Re: bug#59754: [PATCH] scripts: repl: Add --interactive and --list-types flags.
(name . Antero Mejr)(address . antero@mailbox.org)
87cz7ebmpt.fsf_-_@gmail.com
Hello,

Antero Mejr <antero@mailbox.org> writes:

Toggle quote (4 lines)
> * guix/scripts/repl.scm (%options): Add -i, --interactive flag.
> (guix-repl): Honor -i, --interactive flag.
> * doc/guix.texi (Invoking guix repl): Add documentation for -i, --interactive.

I've added your copyright to the guix.texi file and made a small
adjustment, as shown below:

Toggle snippet (20 lines)
modified doc/guix.texi
@@ -111,6 +111,7 @@ Copyright @copyright{} 2022 (@*
Copyright @copyright{} 2022 John Kehayias@*
Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
Copyright @copyright{} 2023 Giacomo Leidi@*
+Copyright @copyright{} 2022 Antero Mejr@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -12070,7 +12071,7 @@ Accept connections on the Unix-domain socket @file{/tmp/socket}.
@item --interactive
@itemx -i
-Launch the interactive REPL after @var{FILE} is executed.
+Launch the interactive REPL after @var{file} is executed.
@item --load-path=@var{directory}
@itemx -L @var{directory}

And pushed! Thanks for the contribution and to Simon for the review!

--
Thanks,
Maxim
Closed
?