Merge pull request #23401 from taosdata/feat/TD-26873-MAIN

feat: add env TDENGINE_DSN to taos-CLI
This commit is contained in:
Alex Duan 2023-10-26 14:14:52 +08:00 committed by GitHub
commit 7cac655fc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 3 deletions

View File

@ -80,6 +80,7 @@ typedef struct {
#ifdef WEBSOCKET #ifdef WEBSOCKET
bool restful; bool restful;
bool cloud; bool cloud;
bool local;
char* dsn; char* dsn;
int32_t timeout; int32_t timeout;
#endif #endif

View File

@ -409,8 +409,12 @@ static int32_t shellCheckArgs() {
int32_t shellParseArgs(int32_t argc, char *argv[]) { int32_t shellParseArgs(int32_t argc, char *argv[]) {
shellInitArgs(argc, argv); shellInitArgs(argc, argv);
shell.info.clientVersion = shell.info.clientVersion =
#ifdef WEBSOCKET
"Welcome to the %s Command Line Interface (WebSocket), Client Version:%s\r\n"
#else
"Welcome to the %s Command Line Interface, Client Version:%s\r\n" "Welcome to the %s Command Line Interface, Client Version:%s\r\n"
"Copyright (c) 2022 by %s, all rights reserved.\r\n\r\n"; #endif
"Copyright (c) 2023 by %s, all rights reserved.\r\n\r\n";
#ifdef CUS_NAME #ifdef CUS_NAME
strcpy(shell.info.cusName, CUS_NAME); strcpy(shell.info.cusName, CUS_NAME);
#else #else

View File

@ -47,6 +47,7 @@ int main(int argc, char *argv[]) {
#ifdef WEBSOCKET #ifdef WEBSOCKET
shell.args.timeout = SHELL_WS_TIMEOUT; shell.args.timeout = SHELL_WS_TIMEOUT;
shell.args.cloud = true; shell.args.cloud = true;
shell.args.local = false;
#endif #endif
#if !defined(WINDOWS) #if !defined(WINDOWS)

View File

@ -130,11 +130,21 @@ void shellCheckConnectMode() {
} }
if (shell.args.cloud) { if (shell.args.cloud) {
shell.args.dsn = getenv("TDENGINE_CLOUD_DSN"); shell.args.dsn = getenv("TDENGINE_CLOUD_DSN");
if (shell.args.dsn) { if (shell.args.dsn && strlen(shell.args.dsn) > 4) {
shell.args.cloud = true; shell.args.cloud = true;
shell.args.local = false;
shell.args.restful = false; shell.args.restful = false;
return; return;
} }
shell.args.dsn = getenv("TDENGINE_DSN");
if (shell.args.dsn && strlen(shell.args.dsn) > 4) {
shell.args.cloud = true;
shell.args.local = true;
shell.args.restful = false;
return;
}
if (shell.args.restful) { if (shell.args.restful) {
if (!shell.args.host) { if (!shell.args.host) {
shell.args.host = "localhost"; shell.args.host = "localhost";

View File

@ -59,7 +59,17 @@ int shell_conn_ws_server(bool first) {
fprintf(stdout, "successfully connected to %s\n\n", fprintf(stdout, "successfully connected to %s\n\n",
shell.args.dsn); shell.args.dsn);
} else if (first && shell.args.cloud) { } else if (first && shell.args.cloud) {
fprintf(stdout, "successfully connected to cloud service\n"); if(shell.args.local) {
const char* host = strstr(shell.args.dsn, "@");
if(host) {
host += 1;
} else {
host = shell.args.dsn;
}
fprintf(stdout, "successfully connected to %s\n", host);
} else {
fprintf(stdout, "successfully connected to cloud service\n");
}
} }
fflush(stdout); fflush(stdout);