Skip to content

Commit

Permalink
Merge pull request #6 from Conzxy/dist
Browse files Browse the repository at this point in the history
MOD: options
  • Loading branch information
Conzxy authored Apr 5, 2023
2 parents c4eca26 + 7a9e724 commit 4314730
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
8 changes: 8 additions & 0 deletions mmkv/app/server_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "mmkv/server/option.h"
#include "mmkv/util/conv.h"
#include "mmkv/util/str_util.h"
#include "mmkv/version.h"

#include <kanon/init.h>
#include <kanon/string/string_util.h>
Expand Down Expand Up @@ -32,6 +33,9 @@ int main(int argc, char *argv[])
takina::AddOption(
{"sp", "sharder-port", "Port number of sharder(default: 19998)"},
&mmkv_option().sharder_port);
takina::AddSection("Version information");
takina::AddOption({"v", "version", "Show the current version of mmkv"},
&mmkv_option().version);
const auto success = takina::Parse(argc, argv, &errmsg);
if (!success) {
::fprintf(stderr, "Failed to parse the options: \n%s\n", errmsg.c_str());
Expand All @@ -40,6 +44,10 @@ int main(int argc, char *argv[])
takina::Teardown();
LOG_INFO << "Options has parsed successfully";

if (mmkv_option().version) {
printf("mmkv v%s\n", MMKV_VERSION_STR);
return 0;
}
// RegisterConfig(mmkv_config());
// if (!ParseConfig(errmsg)) {
// ::fprintf(stderr, "Failed to parse the config file: \n%s\n",
Expand Down
11 changes: 8 additions & 3 deletions mmkv/client/option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ void RegisterOptions()
takina::AddUsage("./mmkv_cli [OPTIONS]");
takina::AddDescription("Command-line-interface client of mmkv");

takina::AddOption({"l", "log", "Enable log trace/debug/... message"},
&cli_option().log);
takina::AddSection("Connect control");
takina::AddOption({"p", "port", "Port of mmkv server", "PORT"},
&cli_option().port);
takina::AddOption({"h", "host", "Hostname of mmkv server", "HOST"},
&cli_option().host);
takina::AddOption(
{"r", "reconnect", "Reconnect to server when peer close the connection"},
&cli_option().reconnect);
takina::AddOption({"v", "version", "Show current version of mmkv"},

takina::AddSection("Log control");
takina::AddOption({"l", "log", "Enable log trace/debug/... message"},
&cli_option().log);

takina::AddSection("Version information");
takina::AddOption({"v", "version", "Show the current version of mmkv"},
&cli_option().version);
}

Expand Down
7 changes: 4 additions & 3 deletions mmkv/server/option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace mmkv {
namespace server {

MmkvOption &mmkv_option() {
MmkvOption &mmkv_option()
{
static MmkvOption option;
return option;
}

} // server
} // mmkv
} // namespace server
} // namespace mmkv
5 changes: 3 additions & 2 deletions mmkv/server/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ struct MmkvOption {
int port = 9998;
std::string ip = "any";
int sharder_port = port + BACKGROUND_PORT_DIFF;
bool version = false;
};

MmkvOption &mmkv_option();

} // option
} // mmkv
} // namespace server
} // namespace mmkv

#endif

0 comments on commit 4314730

Please sign in to comment.