mbox

[bug#45893,v2,0/3] DRAFT: Hint command line typo

Message ID 865z3xlp2y.fsf@gmail.com
Headers show

Message

Simon Tournier Jan. 16, 2021, 12:09 a.m. UTC
Hi,

Here a v2 with some revamp.  It looks like this:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix show --laod-pth hello
hint: Do you mean `load-path'?

guix show: error: laod-pth: unrecognized option

$ ./pre-inst-env guix chow --laod-pth hello
hint: Do you mean `show'?

guix: chow: command not found
Try `guix --help' for more information.

$ ./pre-inst-env guix abcde
hint: Do you mean `archive', `gc', `pack', `size'?

guix: abcde: command not found
Try `guix --help' for more information.

$ ./pre-inst-env guix show --abcdefijk hello
hint: Do you mean `help', `version', `load-path'?

guix show: error: abcdefijk: unrecognized option
--8<---------------cut here---------------end--------------->8---

First, the v2 remove of car, cdr etc in favor of ’match’.  And, I do not
know if my Emacs has the correct setup for indentation.  Sorry for that.

Second, the 3 added pieces are:

 1. levenshtein-distance and string-closest in guix/utils.scm (patch 2)
 2. option-hint in guix/scripts.scm (patch 2)
 3. command-hint in guix/ui.scm (patch 3)

#1 eases the reuses.  Well, guix/utils.scm because I lacked imagination.

The option-hint is only added in ’parse-command-line’ and not
’args-fold*’ therefore currently this hint does not work for all the
subcommand.  That’s the reason of the first patch that fixes for “guix
search” and “guix show”.  If it is makes sense, I can easily replace all
the ’args-fold*’ by ’parse-command-line’.  I am in favor of that for 2
reasons:

 a) one function to do one thing
 b) recommend this parse-command-line function for the new extensions

Last, in this mood, a hint is added to the subcommand itself.  Well, I
am not sure it makes sense…  Well, that’s just a proposal.

Ah, I have not been inspired by the commit message. :-)

All the best,
simon

zimoun (3):
  scripts: search, show: Replace 'args-fold*' by 'parse-command-line'.
  guix: scripts: Add hint for option typo.
  ui: Add command hint.

 guix/scripts.scm        | 21 +++++++++++++++++
 guix/scripts/search.scm |  7 ++----
 guix/scripts/show.scm   |  8 ++-----
 guix/ui.scm             | 16 +++++++++++++
 guix/utils.scm          | 51 ++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 91 insertions(+), 12 deletions(-)


base-commit: 884f320e7ceb35cb8472510e47fc5f1944675d82
--
2.29.2