From 86c818a98a18a3b6c33a494202922f1cd275ac7b Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Wed, 11 May 2011 02:39:14 +0000 Subject: cli: taking my revenge for forcing "geo-replication" into commandline Accept unambigous initial fragments of keywords, eg. gluster vol geo stat is recognized. Compared to readline integration: - no external dependency - works in shell too - works for inner keywords of operations (as in above example, or "vol crea repl 3 ...") - you save pressing tabs :) If not desired in customer builds, can be disabled by an #ifdef (not integrated into build system as of now); however, I think folks in house could like it. Signed-off-by: Csaba Henk Signed-off-by: Anand Avati BUG: 2757 (refactory gsync/gsyncd/syncdaemon/whatever to geo-replication) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2757 --- cli/src/registry.c | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'cli/src/registry.c') diff --git a/cli/src/registry.c b/cli/src/registry.c index 8fa116a48c7..bab44cd8996 100644 --- a/cli/src/registry.c +++ b/cli/src/registry.c @@ -260,29 +260,49 @@ err: return NULL; } - -struct cli_cmd_word * -cli_cmd_nextword (struct cli_cmd_word *word, const char *token) +void * +cli_getunamb (const char *tok, void **choices, cli_selector_t sel) { - struct cli_cmd_word *next = NULL; - struct cli_cmd_word **trav = NULL; - int ret = 0; + void **wcon = NULL; + char *w = NULL; + unsigned mn = 0; + void *ret = NULL; - if (!word->nextwords) + if (!choices || !*tok) return NULL; - for (trav = word->nextwords; (next = *trav); trav++) { - if (next->match) { -// ret = next->match (); - } else { - ret = strcmp (next->word, token); - } + for (wcon = choices; *wcon; wcon++) { + w = strtail ((char *)sel (*wcon), tok); + if (!w) + /* no match */ + continue; + if (!*w) + /* exact match */ + return *wcon; - if (ret == 0) - break; + ret = *wcon; + mn++; } - return next; +#ifdef FORCE_MATCH_EXACT + return NULL; +#else + return (mn == 1) ? ret : NULL; +#endif +} + +static const char * +sel_cmd_word (void *wcon) +{ + return ((struct cli_cmd_word *)wcon)->word; +} + +struct cli_cmd_word * +cli_cmd_nextword (struct cli_cmd_word *word, const char *token) +{ + return (struct cli_cmd_word *)cli_getunamb (token, + (void **)word->nextwords, + sel_cmd_word); } -- cgit