提交 a2d6a81f 编写于 作者: W Wu Tao 提交者: QinZuoyan

shell: implement cc command (#196)

上级 417c6266
......@@ -544,6 +544,20 @@ inline bool use_app_as_current(command_executor *e, shell_context *sc, arguments
}
}
extern void check_in_cluster(std::string cluster_name);
inline bool cc_command(command_executor *e, shell_context *sc, arguments args)
{
if (args.argc == 2) {
std::string cluster_name = args.argv[1];
if (!cluster_name.empty()) {
check_in_cluster(cluster_name);
return true;
}
}
return false;
}
inline bool process_escape_all(command_executor *e, shell_context *sc, arguments args)
{
if (args.argc == 1) {
......
......@@ -101,6 +101,9 @@ static command_executor commands[] = {
"[app_name]",
use_app_as_current,
},
{
"cc", "check in the specified cluster", "[cluster_name]", cc_command,
},
{
"escape_all",
"if escape all characters when printing key/value bytes",
......@@ -507,22 +510,8 @@ static char *hintsCallback(const char *buf, int *color, int *bold)
/* Linenoise free hints callback. */
static void freeHintsCallback(void *ptr) { sdsfree((sds)ptr); }
void initialize(int argc, char **argv)
/*extern*/ void check_in_cluster(std::string cluster_name)
{
std::cout << "Pegasus Shell " << PEGASUS_VERSION << std::endl;
std::cout << "Type \"help\" for more information." << std::endl;
std::cout << "Type \"Ctrl-D\" or \"Ctrl-C\" to exit the shell." << std::endl;
std::cout << std::endl;
std::string config_file = argc > 1 ? argv[1] : "config.ini";
if (!pegasus::pegasus_client_factory::initialize(config_file.c_str())) {
std::cout << "ERROR: init pegasus failed: " << config_file << std::endl;
dsn_exit(-1);
} else {
std::cout << "The config file is: " << config_file << std::endl;
}
std::string cluster_name = argc > 2 ? argv[2] : "mycluster";
s_global_context.current_cluster_name = cluster_name;
std::string section = "uri-resolver.dsn://" + s_global_context.current_cluster_name;
std::string key = "arguments";
......@@ -530,8 +519,8 @@ void initialize(int argc, char **argv)
dsn::replication::replica_helper::load_meta_servers(
s_global_context.meta_list, section.c_str(), key.c_str());
s_global_context.ddl_client.reset(
new dsn::replication::replication_ddl_client(s_global_context.meta_list));
s_global_context.ddl_client =
dsn::make_unique<dsn::replication::replication_ddl_client>(s_global_context.meta_list);
// get real cluster name from zk
std::string name;
......@@ -541,6 +530,25 @@ void initialize(int argc, char **argv)
}
std::cout << "The cluster name is: " << cluster_name << std::endl;
std::cout << "The cluster meta list is: " << server_list << std::endl;
}
void initialize(int argc, char **argv)
{
std::cout << "Pegasus Shell " << PEGASUS_VERSION << std::endl;
std::cout << "Type \"help\" for more information." << std::endl;
std::cout << "Type \"Ctrl-D\" or \"Ctrl-C\" to exit the shell." << std::endl;
std::cout << std::endl;
std::string config_file = argc > 1 ? argv[1] : "config.ini";
if (!pegasus::pegasus_client_factory::initialize(config_file.c_str())) {
std::cout << "ERROR: init pegasus failed: " << config_file << std::endl;
dsn_exit(-1);
} else {
std::cout << "The config file is: " << config_file << std::endl;
}
std::string cluster_name = argc > 2 ? argv[2] : "mycluster";
check_in_cluster(cluster_name);
linenoiseSetMultiLine(1);
linenoiseSetCompletionCallback(completionCallback);
......@@ -586,7 +594,6 @@ int main(int argc, char **argv)
return 0;
}
#if defined(__linux__)
#include <dsn/git_commit.h>
#include <dsn/version.h>
#include <pegasus/git_commit.h>
......@@ -603,4 +610,3 @@ static char const rcsid[] =
#endif
", built at " __DATE__ " " __TIME__ " $";
const char *pegasus_shell_rcsid() { return rcsid; }
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册