From 3c99862911ba19842dc10ef46169cce0d4d51f53 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 24 Nov 2022 18:02:05 +0800 Subject: [PATCH] fix(shell): add help command and fixed fields auto fill --- src/kit/shell/inc/shellAuto.h | 2 ++ src/kit/shell/src/shellAuto.c | 42 +++++++++++++++++++++------------ src/kit/shell/src/shellEngine.c | 6 +++++ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/kit/shell/inc/shellAuto.h b/src/kit/shell/inc/shellAuto.h index 0bd6bdf403..51fd4656ec 100644 --- a/src/kit/shell/inc/shellAuto.h +++ b/src/kit/shell/inc/shellAuto.h @@ -33,5 +33,7 @@ void shellAutoExit(); // callback autotab module void callbackAutoTab(char* sqlstr, TAOS* pSql, bool usedb); +// show all commands help +void showHelp(); #endif diff --git a/src/kit/shell/src/shellAuto.c b/src/kit/shell/src/shellAuto.c index a96aa3f581..1b814e525f 100644 --- a/src/kit/shell/src/shellAuto.c +++ b/src/kit/shell/src/shellAuto.c @@ -1438,25 +1438,37 @@ bool matchSelectQuery(TAOS * con, Command * cmd) { } // if is input create fields or tags area, return true -bool isCreateFieldsArea(char * p) { - char * left = strrchr(p, '('); - if (left == NULL) { - // like 'create table st' - return false; - } +bool isCreateFieldsArea(char* p) { + // put to while, support like create table st(ts timestamp, bin1 binary(16), bin2 + blank + TAB + char* p1 = strdup(p); + bool ret = false; + while (1) { + char* left = strrchr(p1, '('); + if (left == NULL) { + // like 'create table st' + ret = false; + break; + } - char * right = strrchr(p, ')'); - if(right == NULL) { - // like 'create table st( ' - return true; - } + char* right = strrchr(p1, ')'); + if (right == NULL) { + // like 'create table st( ' + ret = true; + break; + } - if (left > right) { - // like 'create table st( ts timestamp, age int) tags(area ' - return true; + if (left > right) { + // like 'create table st( ts timestamp, age int) tags(area ' + ret = true; + break; + } + + // set string end by small for next strrchr search + *left = 0; } + taosMemoryFree(p1); - return false; + return ret; } bool matchCreateTable(TAOS * con, Command * cmd) { diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 2777653517..e364639a99 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -216,6 +216,12 @@ int32_t shellRunCommand(TAOS* con, char* command) { return 0; } + // add help or help; + if (strcmp(command, "help") == 0 || strcmp(command, "help;") == 0) { + showHelp(); + return 0; + } + /* Update the history vector. */ if (history.hstart == history.hend || history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE] == NULL || -- GitLab