From ff5160e35cd85168baab66caa80cf1ed03672c33 Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@icir.org>
Date: Tue, 14 Nov 2006 15:39:03 +0000
Subject: [PATCH] fix "core set debug atleast ", and fix the simple case where
 a command can have multiple completions, the first ones coming from keywords
 in previous CLI entries.

There is no solution yet for the complex case of N1 completions
from a CLI entry, followed by N2 from the next one, and so on,
because the _complete() handlers do not tell us how many matches
it generates, so we don't know how many to skip when interrogating
the other handlers.

The only solution is to avoid, as much as possible, multiple
CLI entries with the same prefix.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47607 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/cli.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/main/cli.c b/main/cli.c
index 5949085e01..127aa19aba 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -274,7 +274,7 @@ static int handle_set_debug(int fd, int argc, char *argv[])
 	}
 	if (!strcasecmp(argv[e->args], "atleast"))
 		atleast = 1;
-	if (argc > e->args + atleast + 2)
+	if (argc < e->args + atleast + 1 || argc > e->args + atleast + 2)
 		return RESULT_SHOWUSAGE;
 	if (sscanf(argv[e->args + atleast], "%d", &newlevel) != 1)
 		return RESULT_SHOWUSAGE;
@@ -1675,7 +1675,7 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
 					.fake = "-",
 					.line = matchstr, .word = word,
 					.pos = argindex,
-					.n = state };
+					.n = state - matchnum };
 				char *args[] = { (char *)e, (char *)&a, NULL };
 				ret = (char *)e->handler(-1, CLI_GENERATE, args + 1);
 			}
-- 
GitLab