Skip to content

Commit

Permalink
Add --help cmd option
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Nov 29, 2024
1 parent 6c53f83 commit d811512
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/echoclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ void run(bool debug, TAddress address)
}
}

void usage(const char* name) {
std::cerr << name << " [--port 80] [--addr 127.0.0.1] [--method select|poll|epoll|kqueue] [--debug] [--help]" << std::endl;
std::exit(1);
}

int main(int argc, char** argv) {
TInitializer init;
std::string addr = "127.0.0.1";
Expand All @@ -65,6 +70,8 @@ int main(int argc, char** argv) {
method = argv[++i];
} else if (!strcmp(argv[i], "--debug")) {
debug = true;
} else if (!strcmp(argv[i], "--help")) {
usage(argv[0]);
}
}
if (port == 0) { port = 8888; }
Expand Down
7 changes: 7 additions & 0 deletions examples/echoserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void run(bool debug, TAddress address, int buffer_size)
loop.Loop();
}

void usage(const char* name) {
std::cerr << name << " [--port 80] [--method select|poll|epoll|kqueue] [--debug] [--buffer-size 100000] [--help]" << std::endl;
std::exit(1);
}

int main(int argc, char** argv) {
NNet::TInitializer init;
int port = 0;
Expand All @@ -77,6 +82,8 @@ int main(int argc, char** argv) {
debug = true;
} else if (!strcmp(argv[i], "--buffer-size") && i < argc-1) {
buffer_size = atoi(argv[++i]);
} else if (!strcmp(argv[i], "--help")) {
usage(argv[0]);
}
}
if (port == 0) { port = 8888; }
Expand Down
7 changes: 7 additions & 0 deletions examples/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ void run(EDNSType type) {
}
}

void usage(const char* name) {
std::cerr << name << " [--method select|poll|epoll|kqueue] [--ipv6] [--help] < addr_file.txt" << std::endl;
std::exit(1);
}

int main(int argc, char** argv) {
std::string method = "poll";
EDNSType type = EDNSType::A;
Expand All @@ -56,6 +61,8 @@ int main(int argc, char** argv) {
method = argv[++i];
} else if (!strcmp(argv[i], "--ipv6")) {
type = EDNSType::AAAA;
} else if (!strcmp(argv[i], "--help")) {
usage(argv[i]);
}
}

Expand Down

0 comments on commit d811512

Please sign in to comment.