Skip to content

Commit abd1794

Browse files
authored
refactor(FQDN): update some logs in cpp-shell CLI (#2064)
1 parent 102e087 commit abd1794

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

src/shell/command_utils.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,32 @@
2626
#include "utils/error_code.h"
2727

2828
bool validate_ip(shell_context *sc,
29-
const std::string &ip_str,
29+
const std::string &target_hp_str,
3030
dsn::host_port &target_hp,
3131
std::string &err_info)
3232
{
33-
target_hp = dsn::host_port::from_string(ip_str);
33+
target_hp = dsn::host_port::from_string(target_hp_str);
3434
if (!target_hp) {
35-
err_info = fmt::format("invalid ip:port={}, can't transform it into host_port", ip_str);
35+
err_info =
36+
fmt::format("invalid host:port '{}', can't transform it into host_port", target_hp_str);
3637
return false;
3738
}
3839

39-
std::map<dsn::host_port, dsn::replication::node_status::type> nodes;
40-
auto error = sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, nodes);
40+
std::map<dsn::host_port, dsn::replication::node_status::type> ns_by_nodes;
41+
const auto error =
42+
sc->ddl_client->list_nodes(dsn::replication::node_status::NS_INVALID, ns_by_nodes);
4143
if (error != dsn::ERR_OK) {
42-
err_info = fmt::format("list nodes failed, error={}", error.to_string());
44+
err_info = fmt::format("list nodes failed, error={}", error);
4345
return false;
4446
}
4547

46-
for (const auto &node : nodes) {
47-
if (target_hp == node.first) {
48+
for (const auto &[node, _] : ns_by_nodes) {
49+
if (target_hp == node) {
4850
return true;
4951
}
5052
}
5153

52-
err_info = fmt::format("invalid ip:port={}, can't find it in the cluster", ip_str);
54+
err_info = fmt::format("invalid host:port '{}', can't find it in the cluster", target_hp_str);
5355
return false;
5456
}
5557

src/shell/command_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ inline bool validate_cmd(const argh::parser &cmd,
6666
}
6767

6868
bool validate_ip(shell_context *sc,
69-
const std::string &ip_str,
69+
const std::string &host_port_str,
7070
/*out*/ dsn::host_port &target_hp,
7171
/*out*/ std::string &err_info);
7272

src/shell/commands/detect_hotkey.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ bool detect_hotkey(command_executor *e, shell_context *sc, arguments args)
102102

103103
dsn::host_port target_hp;
104104
std::string err_info;
105-
std::string ip_str = cmd({"-d", "--address"}).str();
106-
if (!validate_ip(sc, ip_str, target_hp, err_info)) {
105+
const auto &target_hp_str = cmd({"-d", "--address"}).str();
106+
if (!validate_ip(sc, target_hp_str, target_hp, err_info)) {
107107
fmt::print(stderr, "{}\n", err_info);
108108
return false;
109109
}
@@ -145,7 +145,7 @@ bool detect_hotkey(command_executor *e, shell_context *sc, arguments args)
145145
app_id,
146146
partition_index,
147147
hotkey_type,
148-
ip_str);
148+
target_hp_str);
149149
break;
150150
case dsn::replication::detect_action::STOP:
151151
fmt::print("Hotkey detection is stopped now\n");

src/shell/commands/node_management.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ bool remote_command(command_executor *e, shell_context *sc, arguments args)
638638
for (std::string &token : tokens) {
639639
const auto node = dsn::host_port::from_string(token);
640640
if (!node) {
641-
fprintf(stderr, "parse %s as a ip:port node failed\n", token.c_str());
641+
fprintf(stderr, "parse %s as a host:port node failed\n", token.c_str());
642642
return true;
643643
}
644644
node_list.emplace_back("user-specified", node);

src/shell/commands/recovery.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool recover(command_executor *e, shell_context *sc, arguments args)
118118
for (std::string &token : tokens) {
119119
const auto node = dsn::host_port::from_string(token);
120120
if (!node) {
121-
fprintf(stderr, "parse %s as a ip:port node failed\n", token.c_str());
121+
fprintf(stderr, "parse %s as a host:port node failed\n", token.c_str());
122122
return true;
123123
}
124124
node_list.push_back(node);
@@ -140,7 +140,7 @@ bool recover(command_executor *e, shell_context *sc, arguments args)
140140
const auto node = dsn::host_port::from_string(str);
141141
if (!node) {
142142
fprintf(stderr,
143-
"parse %s at file %s line %d as ip:port failed\n",
143+
"parse %s at file %s line %d as host:port failed\n",
144144
str.c_str(),
145145
node_list_file.c_str(),
146146
lineno);

src/shell/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,20 @@ static command_executor commands[] = {
372372
{
373373
"remote_command",
374374
"send remote command to servers",
375-
"[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l ip:port,ip:port...]"
375+
"[-t all|meta-server|replica-server] [-r|--resolve_ip] [-l host:port,host:port...]"
376376
" <command> [arguments...]",
377377
remote_command,
378378
},
379379
{
380380
"server_info",
381381
"get info of servers",
382-
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] [-r|--resolve_ip]",
382+
"[-t all|meta-server|replica-server] [-l host:port,host:port...] [-r|--resolve_ip]",
383383
server_info,
384384
},
385385
{
386386
"server_stat",
387387
"get stat of servers",
388-
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...] [-r|--resolve_ip]",
388+
"[-t all|meta-server|replica-server] [-l host:port,host:port...] [-r|--resolve_ip]",
389389
server_stat,
390390
},
391391
{
@@ -398,7 +398,7 @@ static command_executor commands[] = {
398398
{
399399
"flush_log",
400400
"flush log of servers",
401-
"[-t all|meta-server|replica-server] [-l ip:port,ip:port...][-r|--resolve_ip]",
401+
"[-t all|meta-server|replica-server] [-l host:port,host:port...][-r|--resolve_ip]",
402402
flush_log,
403403
},
404404
{

0 commit comments

Comments
 (0)