Re: [PATCH] help.c: add advice.correctTypos option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Drew DeVault <sir@xxxxxxxxx> writes:

> This allows users to disable guessing the commands or options that they
> meant to use.
> ---
> Questions:
>
> - Is advice.* the right namespace?
> - How should this interact with help.autocorrect?

If you are declining help.autocorrect altogether, do you need to
still invent a new and separate configuration variable?  Isn't a new
value (e.g. 'never') given to help.autocorrect sufficient?

Something along this line (not even compile tested though)?

 help.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git c/help.c w/help.c
index 4fb93d5560..06f86152a6 100644
--- c/help.c
+++ w/help.c
@@ -469,6 +469,8 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
 	return 0;
 }
 
+#define AUTOCORRECT_NEVER (-2)
+#define AUTOCORRECT_IMMEDIATELY (-1)
 static int autocorrect;
 static struct cmdnames aliases;
 
@@ -476,8 +478,19 @@ static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
 {
 	const char *p;
 
-	if (!strcmp(var, "help.autocorrect"))
-		autocorrect = git_config_int(var,value);
+	if (!strcmp(var, "help.autocorrect")) {
+		if (!value)
+			return config_error_nonbool(var);
+		if (!strcmp(value, "never"))
+			autocorrect = AUTOCORRECT_NEVER;
+		else {
+			int v = git_config_int(var,value);
+			if (v < 0)
+				autocorrect = AUTOCORRECT_IMMEDIATELY;
+			else
+				autocorrect = v;
+		}
+	}
 	/* Also use aliases for command lookup */
 	if (skip_prefix(var, "alias.", &p))
 		add_cmdname(&aliases, p, strlen(p));
@@ -519,6 +532,9 @@ const char *help_unknown_cmd(const char *cmd)
 	struct cmdnames main_cmds, other_cmds;
 	struct cmdname_help *common_cmds;
 
+	if (autocorrect == AUTOCORRECT_NEVER)
+		exit(1);
+
 	memset(&main_cmds, 0, sizeof(main_cmds));
 	memset(&other_cmds, 0, sizeof(other_cmds));
 	memset(&aliases, 0, sizeof(aliases));
@@ -594,7 +610,7 @@ const char *help_unknown_cmd(const char *cmd)
 			   _("WARNING: You called a Git command named '%s', "
 			     "which does not exist."),
 			   cmd);
-		if (autocorrect < 0)
+		if (autocorrect == AUTOCORRECT_IMMEDIATELY)
 			fprintf_ln(stderr,
 				   _("Continuing under the assumption that "
 				     "you meant '%s'."),



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux