MCPcopy Create free account
hub / github.com/cybozu/yrmcds / optparse

Function optparse

test/protocol_binary.cpp:1255–1288  ·  view source on GitHub ↗

main

Source from the content-addressed store, hash-verified

1253
1254// main
1255bool optparse(int argc, char** argv) {
1256 if( argc > 3 ) {
1257 print_usage();
1258 return false;
1259 }
1260
1261 g_server = getenv("YRMCDS_SERVER");
1262 const char* env_port = getenv("YRMCDS_PORT");
1263 if( env_port != nullptr )
1264 g_port = std::stoi(env_port);
1265
1266 if( argc >= 2 )
1267 g_server = argv[1];
1268 if( argc >= 3 )
1269 g_port = std::stoi(argv[2]);
1270
1271 if( g_server == nullptr ) {
1272 std::cout << "No server specified." << std::endl;
1273 print_usage();
1274 return false;
1275 }
1276 if( g_port <= 0 || g_port > 65535 ) {
1277 std::cout << "Invalid port number: " << g_port << std::endl;
1278 return false;
1279 }
1280
1281 int s = connect_server();
1282 if( s == -1 ) {
1283 std::cout << "Failed to connect to " << g_server << std::endl;
1284 return false;
1285 }
1286 ::close(s);
1287 return true;
1288}
1289
1290TEST_MAIN(optparse);

Callers

nothing calls this directly

Calls 2

print_usageFunction · 0.70
connect_serverFunction · 0.70

Tested by

no test coverage detected