[PATCH 0/1] Fix 2 corner cases for option hint

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • zimoun
Owner
unassigned
Submitted by
zimoun
Severity
normal
Z
Z
zimoun wrote on 5 Feb 2021 00:00
(address . guix-patches@gnu.org)(name . zimoun)(address . zimon.toutoune@gmail.com)
20210204230028.2275-1-zimon.toutoune@gmail.com
Hi,

First,

Toggle snippet (4 lines)
$ guix package --shw=hello
guix package: error: shw=hello: unrecognized option

becomes

Toggle snippet (5 lines)
$ ./pre-inst-env guix package --shw=hello
guix package: error: shw=hello: unrecognized option
hint: Did you mean `show'?

And second the ugly (introduced by ’option’hint):

Toggle snippet (29 lines)
$ guix package -Z
Backtrace:
11 (primitive-load "/home/simon/.config/guix/current/bin/guix")
In guix/ui.scm:
2162:12 10 (run-guix-command _ . _)
In guix/scripts/package.scm:
1075:2 9 (guix-package . _)
In ice-9/boot-9.scm:
1731:15 8 (with-exception-handler #<procedure 7fc66e356f00 at ice-9/boot-9.scm:1815:7 (exn)> _ # _ …)
In srfi/srfi-37.scm:
113:18 7 (next-arg)
In unknown file:
6 (_ #<procedure 7fc66e356ea0 at srfi/srfi-37.scm:114:22 ()> #<procedure list _> #<hash-t…>)
In guix/scripts.scm:
121:2 5 (_ _ #\Z _ . _)
In guix/utils.scm:
920:4 4 (string-closest _ _ #:threshold _)
In guix/combinators.scm:
46:26 3 (fold2 #<procedure 7fc66e24a660 at guix/utils.scm:920:11 (test closest minimal)> #f # (…))
In guix/utils.scm:
921:25 2 (_ "help" #f +inf.0)
911:12 1 (string-distance #\Z "help")
In unknown file:
0 (string->list #\Z #<undefined> #<undefined>)

ERROR: In procedure string->list:
In procedure string->list: Wrong type argument in position 1 (expecting string): #\Z

is fixed:

Toggle snippet (5 lines)
$ ./pre-inst-env guix package -Z
guix package: error: Z: unrecognized option


A corner case is still missing:

$ ./pre-inst-env guix environment -ah-hoc hello
guix environment: error: a: unrecognized option

where it could be nice to hint for. But from my understanding, it is not possible with SRFI-37.


All the best,
simon

zimoun (1):
guix: scripts: Fix corner cases of hint for option typo.

guix/scripts.scm | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)


base-commit: 5ae09d7979a0696d862b9555314eab199f7ce576
--
2.29.2
Z
Z
zimoun wrote on 5 Feb 2021 00:02
[PATCH 1/1] guix: scripts: Fix corner cases of hint for option typo.
(address . 46308@debbugs.gnu.org)(name . zimoun)(address . zimon.toutoune@gmail.com)
20210204230250.3304-1-zimon.toutoune@gmail.com
* guix/scripts.scm (option-hint): Fix corner cases.
---
guix/scripts.scm | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

Toggle diff (20 lines)
diff --git a/guix/scripts.scm b/guix/scripts.scm
index c9ea9f2e29..1773894bc2 100644
--- a/guix/scripts.scm
+++ b/guix/scripts.scm
@@ -118,7 +118,12 @@ procedure, but both the category and synopsis are meant to be read (parsed) by
according to'string-distance'."
(define (options->long-names options)
(filter string? (append-map option-names options)))
- (string-closest guess (options->long-names options) #:threshold 3))
+ (match guess
+ ((? string?)
+ (match (string-split guess #\=)
+ ((name rest ...)
+ (string-closest name (options->long-names options) #:threshold 3))))
+ (_ #f)))
(define (args-fold* args options unrecognized-option-proc operand-proc . seeds)
"A wrapper on top of `args-fold' that does proper user-facing error
--
2.29.2
L
L
Ludovic Courtès wrote on 24 Feb 2021 23:51
Re: bug#46308: [PATCH 0/1] Fix 2 corner cases for option hint
(name . zimoun)(address . zimon.toutoune@gmail.com)(address . 46308-done@debbugs.gnu.org)
877dmx2i5y.fsf_-_@gnu.org
Hi,

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

Toggle quote (2 lines)
> * guix/scripts.scm (option-hint): Fix corner cases.

Applied! I also reverted the change I made in
11f11d7ecb817d1421f8b5340bcced59396d8708, which addressed the
short-option problem you mention.

Thanks,
Ludo’.
Closed
?