mbox

[bug#45893,0/2] DRAFT: Hint for options.

Message ID 20210115163732.53665-1-zimon.toutoune@gmail.com
Headers show

Message

Simon Tournier Jan. 15, 2021, 4:37 p.m. UTC
Hi,

The first patch uniformize.  If this proposal is ok, then more Guix scripts
have to be replaced; so the v2 could do that.

The second patch is the interesting one.  The naive implementation of Levenshtein
distance by recursion is enough here when memoize is applied.  However, the 'car'
and 'cdr' is not in the Guix style, feedback welcome.

Maybe abuse of fold, again feeback welcome.


Well, the current result is:

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

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


All the best,
simon


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

 guix/scripts.scm        | 58 +++++++++++++++++++++++++++++++++++++++++
 guix/scripts/search.scm |  7 ++---
 guix/scripts/show.scm   |  8 ++----
 3 files changed, 62 insertions(+), 11 deletions(-)


base-commit: c03875b0361f114634caeb54935fe37a9b7b05af

Comments

Simon Tournier Jan. 16, 2021, 12:09 a.m. UTC | #1
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