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
bool restful;
bool cloud;
bool local;
char* dsn;
int32_t timeout;
#endif

View File

@ -409,8 +409,12 @@ static int32_t shellCheckArgs() {
int32_t shellParseArgs(int32_t argc, char *argv[]) {
shellInitArgs(argc, argv);
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"
"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
strcpy(shell.info.cusName, CUS_NAME);
#else

View File

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

View File

@ -130,11 +130,21 @@ void shellCheckConnectMode() {
}
if (shell.args.cloud) {
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.local = false;
shell.args.restful = false;
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.host) {
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",
shell.args.dsn);
} 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);