Thread (8 messages) flat view 8 messages, 4 authors, 2016-06-15

Re: Doesn't disambiguate between 'external command failed' and 'command not found'

From: Jeff King <hidden>
Date: 2016-06-15 22:51:32
Subsystem: the rest · Maintainer: Linus Torvalds

On Tue, Jul 05, 2011 at 07:16:05PM -0400, Jeff King wrote:
So if you are going to follow this strategy, you are probably better to
just skip the entry (or give it a high levenshtein distance) in the main
loop where we calculate candidates.
And here's what that would look like.
diff --git a/help.c b/help.c
index e925ca1..15e6f0b 100644
--- a/help.c
+++ b/help.c
@@ -329,6 +329,11 @@ const char *help_unknown_cmd(const char *cmd)
 		int cmp = 0; /* avoid compiler stupidity */
 		const char *candidate = main_cmds.names[i]->name;
 
+		if (!strcmp(candidate, cmd)) {
+			main_cmds.names[i]->len = SIMILARITY_FLOOR + 1;
+			continue;
+		}
+
 		/* Does the candidate appear in common_cmds list? */
 		while (n < ARRAY_SIZE(common_cmds) &&
 		       (cmp = strcmp(common_cmds[n].name, candidate)) < 0)
I suspect it can create its own brand of confusion, though:

  $ cat `which git-broken`
  #!/bin/bogus
  $ git broken
  git: 'broken' is not a git command. See 'git --help'.

At which point I search through my PATH and confirm that indeed,
"git-broken" _is_ a git command. And I'm left on my own to figure out
that it's a broken #!-line.

So I think I prefer giving some more specific advice. Even if we don't
mention "#!" lines explicitly, saying "This exists, but exec didn't
work" is probably more helpful than pretending it's not there. It gives
clueful people an idea of where to start looking for the problem.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help