Commit f5342494 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

src: Format help message and add --version to make man page generation easier

parent 1fd5fdd5
...@@ -1654,14 +1654,18 @@ int run(char **uris, int n) ...@@ -1654,14 +1654,18 @@ int run(char **uris, int n)
} }
} // namespace } // namespace
namespace {
void print_version(std::ostream& out)
{
out << "nghttp nghttp2/" NGHTTP2_VERSION << std::endl;
}
} // namespace
namespace { namespace {
void print_usage(std::ostream& out) void print_usage(std::ostream& out)
{ {
out << "Usage: nghttp [-Oansuv] [-t <SECONDS>] [-w <WINDOW_BITS>] [-W <WINDOW_BITS>]\n" out << "Usage: nghttp [OPTIONS]... <URI>...\n"
<< " [--cert=<CERT>] [--key=<KEY>] [-d <FILE>] [-m <N>]\n" << "HTTP/2 experimental client" << std::endl;
<< " [-p <PRIORITY>] [-M <N>] [-b <ALIGNMENT>]\n"
<< " <URI>..."
<< std::endl;
} }
} // namespace } // namespace
...@@ -1670,7 +1674,8 @@ void print_help(std::ostream& out) ...@@ -1670,7 +1674,8 @@ void print_help(std::ostream& out)
{ {
print_usage(out); print_usage(out);
out << "\n" out << "\n"
<< "OPTIONS:\n" << " <URI> Specify URI to access.\n"
<< "Options:\n"
<< " -v, --verbose Print debug information such as reception/\n" << " -v, --verbose Print debug information such as reception/\n"
<< " transmission of frames and name/value pairs.\n" << " transmission of frames and name/value pairs.\n"
<< " -n, --null-out Discard downloaded data.\n" << " -n, --null-out Discard downloaded data.\n"
...@@ -1720,6 +1725,8 @@ void print_help(std::ostream& out) ...@@ -1720,6 +1725,8 @@ void print_help(std::ostream& out)
<< " padding. Specify 0 to disable padding.\n" << " padding. Specify 0 to disable padding.\n"
<< " --color Force colored log output.\n" << " --color Force colored log output.\n"
<< " --continuation Send large header to test CONTINUATION.\n" << " --continuation Send large header to test CONTINUATION.\n"
<< " --version Display version information and exit.\n"
<< " -h, --help Display this help and exit.\n"
<< std::endl; << std::endl;
} }
} // namespace } // namespace
...@@ -1751,6 +1758,7 @@ int main(int argc, char **argv) ...@@ -1751,6 +1758,7 @@ int main(int argc, char **argv)
{"key", required_argument, &flag, 2}, {"key", required_argument, &flag, 2},
{"color", no_argument, &flag, 3}, {"color", no_argument, &flag, 3},
{"continuation", no_argument, &flag, 4}, {"continuation", no_argument, &flag, 4},
{"version", no_argument, &flag, 5},
{nullptr, 0, nullptr, 0 } {nullptr, 0, nullptr, 0 }
}; };
int option_index = 0; int option_index = 0;
...@@ -1889,6 +1897,10 @@ int main(int argc, char **argv) ...@@ -1889,6 +1897,10 @@ int main(int argc, char **argv)
// continuation option // continuation option
config.continuation = true; config.continuation = true;
break; break;
case 5:
// version option
print_version(std::cout);
exit(EXIT_SUCCESS);
} }
break; break;
default: default:
......
...@@ -72,12 +72,19 @@ int parse_push_config(Config& config, const char *optarg) ...@@ -72,12 +72,19 @@ int parse_push_config(Config& config, const char *optarg)
} }
} // namespace } // namespace
namespace {
void print_version(std::ostream& out)
{
out << "nghttpd nghttp2/" NGHTTP2_VERSION << std::endl;
}
} // namespace
namespace { namespace {
void print_usage(std::ostream& out) void print_usage(std::ostream& out)
{ {
out << "Usage: nghttpd [-DVhpv] [-d <PATH>] [--no-tls] [-b <ALIGNMENT>]\n" out << "Usage: nghttpd [OPTION]... <PORT> <PRIVATE_KEY> <CERT>\n"
<< " <PORT> [<PRIVATE_KEY> <CERT>]" << " or: nghttpd --no-tls [OPTION]... <PORT>\n"
<< std::endl; << "HTTP/2 experimental server" << std::endl;
} }
} // namespace } // namespace
...@@ -86,7 +93,13 @@ void print_help(std::ostream& out) ...@@ -86,7 +93,13 @@ void print_help(std::ostream& out)
{ {
print_usage(out); print_usage(out);
out << "\n" out << "\n"
<< "OPTIONS:\n" << " <PORT> Specify listening port number.\n"
<< " <PRIVATE_KEY> Set path to server's private key. Required\n"
<< " unless --no-tls is specified.\n"
<< " <CERT> Set path to server's certificate. Required\n"
<< " unless --no-tls is specified.\n"
<< "\n"
<< "Options:\n"
<< " -D, --daemon Run in a background. If -D is used, the\n" << " -D, --daemon Run in a background. If -D is used, the\n"
<< " current working directory is changed to '/'.\n" << " current working directory is changed to '/'.\n"
<< " Therefore if this option is used, -d option\n" << " Therefore if this option is used, -d option\n"
...@@ -117,7 +130,8 @@ void print_help(std::ostream& out) ...@@ -117,7 +130,8 @@ void print_help(std::ostream& out)
<< " root. See --htdocs option.\n" << " root. See --htdocs option.\n"
<< " -b, --padding=<N> Add at most <N> bytes to a frame payload as\n" << " -b, --padding=<N> Add at most <N> bytes to a frame payload as\n"
<< " padding. Specify 0 to disable padding.\n" << " padding. Specify 0 to disable padding.\n"
<< " -h, --help Print this help.\n" << " --version Display version information and exit.\n"
<< " -h, --help Display this help and exit.\n"
<< std::endl; << std::endl;
} }
} // namespace } // namespace
...@@ -139,6 +153,7 @@ int main(int argc, char **argv) ...@@ -139,6 +153,7 @@ int main(int argc, char **argv)
{"padding", required_argument, nullptr, 'b'}, {"padding", required_argument, nullptr, 'b'},
{"no-tls", no_argument, &flag, 1}, {"no-tls", no_argument, &flag, 1},
{"color", no_argument, &flag, 2}, {"color", no_argument, &flag, 2},
{"version", no_argument, &flag, 3},
{nullptr, 0, nullptr, 0} {nullptr, 0, nullptr, 0}
}; };
int option_index = 0; int option_index = 0;
...@@ -192,6 +207,10 @@ int main(int argc, char **argv) ...@@ -192,6 +207,10 @@ int main(int argc, char **argv)
// color option // color option
color = true; color = true;
break; break;
case 3:
// version
print_version(std::cout);
exit(EXIT_SUCCESS);
} }
break; break;
default: default:
......
...@@ -462,12 +462,8 @@ void print_version(std::ostream& out) ...@@ -462,12 +462,8 @@ void print_version(std::ostream& out)
namespace { namespace {
void print_usage(std::ostream& out) void print_usage(std::ostream& out)
{ {
out << "Usage: nghttpx [-Dh] [-s|--client|-p] [-b <HOST,PORT>]\n" out << "Usage: nghttpx [OPTIONS]... [<PRIVATE_KEY> <CERT>]\n"
<< " [-f <HOST,PORT>] [-n <CORES>] [-c <NUM>] [-L <LEVEL>]\n" << "A reverse proxy for HTTP/2, HTTP/1 and SPDY." << std::endl;
<< " [OPTIONS...] [<PRIVATE_KEY> <CERT>]\n"
<< "\n"
<< "A reverse proxy for HTTP/2, HTTP/1 and SPDY.\n"
<< std::endl;
} }
} // namespace } // namespace
...@@ -475,17 +471,17 @@ namespace { ...@@ -475,17 +471,17 @@ namespace {
void print_help(std::ostream& out) void print_help(std::ostream& out)
{ {
print_usage(out); print_usage(out);
out << "Positional arguments:\n" out << "\n"
<< " <PRIVATE_KEY> Set path to server's private key. Required\n" << " <PRIVATE_KEY> Set path to server's private key. Required\n"
<< " unless -p, --client or --frontend-no-tls\n" << " unless -p, --client or --frontend-no-tls\n"
<< " are given.\n" << " are given.\n"
<< " <CERT> Set path to server's certificate. Required\n" << " <CERT> Set path to server's certificate. Required\n"
<< " unless -p, --client or --frontend-no-tls\n" << " unless -p, --client or --frontend-no-tls\n"
<< " are given.\n" << " are given.\n"
<< "Options:\n"
<< " The options are categorized into several groups.\n"
<< "\n" << "\n"
<< "OPTIONS:\n" << "Connections:\n"
<< "\n"
<< " Connections:\n"
<< " -b, --backend=<HOST,PORT>\n" << " -b, --backend=<HOST,PORT>\n"
<< " Set backend host and port.\n" << " Set backend host and port.\n"
<< " Default: '" << " Default: '"
...@@ -504,7 +500,7 @@ void print_help(std::ostream& out) ...@@ -504,7 +500,7 @@ void print_help(std::ostream& out)
<< " --backend-ipv6 Resolve backend hostname to IPv6 address\n" << " --backend-ipv6 Resolve backend hostname to IPv6 address\n"
<< " only.\n" << " only.\n"
<< "\n" << "\n"
<< " Performance:\n" << "Performance:\n"
<< " -n, --workers=<CORES>\n" << " -n, --workers=<CORES>\n"
<< " Set the number of worker threads.\n" << " Set the number of worker threads.\n"
<< " Default: " << " Default: "
...@@ -533,7 +529,7 @@ void print_help(std::ostream& out) ...@@ -533,7 +529,7 @@ void print_help(std::ostream& out)
<< " Default: " << " Default: "
<< get_config()->write_burst << "\n" << get_config()->write_burst << "\n"
<< "\n" << "\n"
<< " Timeout:\n" << "Timeout:\n"
<< " --frontend-http2-read-timeout=<SEC>\n" << " --frontend-http2-read-timeout=<SEC>\n"
<< " Specify read timeout for HTTP/2.0 and SPDY frontend\n" << " Specify read timeout for HTTP/2.0 and SPDY frontend\n"
<< " connection. Default: " << " connection. Default: "
...@@ -574,7 +570,7 @@ void print_help(std::ostream& out) ...@@ -574,7 +570,7 @@ void print_help(std::ostream& out)
<< " can be specified by --backend-read-timeout\n" << " can be specified by --backend-read-timeout\n"
<< " and --backend-write-timeout options.\n" << " and --backend-write-timeout options.\n"
<< "\n" << "\n"
<< " SSL/TLS:\n" << "SSL/TLS:\n"
<< " --ciphers=<SUITE> Set allowed cipher list. The format of the\n" << " --ciphers=<SUITE> Set allowed cipher list. The format of the\n"
<< " string is described in OpenSSL ciphers(1).\n" << " string is described in OpenSSL ciphers(1).\n"
<< " If this option is used, --honor-cipher-order\n" << " If this option is used, --honor-cipher-order\n"
...@@ -644,7 +640,7 @@ void print_help(std::ostream& out) ...@@ -644,7 +640,7 @@ void print_help(std::ostream& out)
<< " as a part of protocol string.\n" << " as a part of protocol string.\n"
<< " Default: " << DEFAULT_TLS_PROTO_LIST << "\n" << " Default: " << DEFAULT_TLS_PROTO_LIST << "\n"
<< "\n" << "\n"
<< " HTTP/2.0 and SPDY:\n" << "HTTP/2.0 and SPDY:\n"
<< " -c, --http2-max-concurrent-streams=<NUM>\n" << " -c, --http2-max-concurrent-streams=<NUM>\n"
<< " Set the maximum number of the concurrent\n" << " Set the maximum number of the concurrent\n"
<< " streams in one HTTP/2.0 and SPDY session.\n" << " streams in one HTTP/2.0 and SPDY session.\n"
...@@ -682,7 +678,7 @@ void print_help(std::ostream& out) ...@@ -682,7 +678,7 @@ void print_help(std::ostream& out)
<< " meant for debugging purpose and not intended\n" << " meant for debugging purpose and not intended\n"
<< " to enhance protocol security.\n" << " to enhance protocol security.\n"
<< "\n" << "\n"
<< " Mode:\n" << "Mode:\n"
<< " (default mode) Accept HTTP/2.0, SPDY and HTTP/1.1 over\n" << " (default mode) Accept HTTP/2.0, SPDY and HTTP/1.1 over\n"
<< " SSL/TLS. If --frontend-no-tls is used,\n" << " SSL/TLS. If --frontend-no-tls is used,\n"
<< " accept HTTP/2.0 and HTTP/1.1. The incoming\n" << " accept HTTP/2.0 and HTTP/1.1. The incoming\n"
...@@ -709,7 +705,7 @@ void print_help(std::ostream& out) ...@@ -709,7 +705,7 @@ void print_help(std::ostream& out)
<< " an absolute URI, suitable for use as a\n" << " an absolute URI, suitable for use as a\n"
<< " forward proxy.\n" << " forward proxy.\n"
<< "\n" << "\n"
<< " Logging:\n" << "Logging:\n"
<< " -L, --log-level=<LEVEL>\n" << " -L, --log-level=<LEVEL>\n"
<< " Set the severity level of log output.\n" << " Set the severity level of log output.\n"
<< " INFO, WARNING, ERROR and FATAL.\n" << " INFO, WARNING, ERROR and FATAL.\n"
...@@ -721,7 +717,7 @@ void print_help(std::ostream& out) ...@@ -721,7 +717,7 @@ void print_help(std::ostream& out)
<< " Default: " << " Default: "
<< str_syslog_facility(get_config()->syslog_facility) << "\n" << str_syslog_facility(get_config()->syslog_facility) << "\n"
<< "\n" << "\n"
<< " Misc:\n" << "Misc:\n"
<< " --add-x-forwarded-for\n" << " --add-x-forwarded-for\n"
<< " Append X-Forwarded-For header field to the\n" << " Append X-Forwarded-For header field to the\n"
<< " downstream request.\n" << " downstream request.\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment