feat: add env TDENGINE_DSN to taos-CLI

This commit is contained in:
Alex Duan 2023-10-25 16:46:32 +08:00
parent d58b964b25
commit 368c6d996b
5 changed files with 25 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

@ -410,7 +410,7 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) {
shellInitArgs(argc, argv);
shell.info.clientVersion =
"Welcome to the %s Command Line Interface, Client Version:%s\r\n"
"Copyright (c) 2022 by %s, all rights reserved.\r\n\r\n";
"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.cloud_dsn) {
shell.args.cloud = true;
shell.args.local = false;
shell.args.restful = false;
return;
}
shell.args.dsn = getenv("TDENGINE_DSN");
if (shell.args.dsn) {
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);