shrpx: Add -v, --version option

This commit is contained in:
Tatsuhiro Tsujikawa 2012-11-22 23:08:36 +09:00
parent 774e64d2b4
commit c1332a35a5
1 changed files with 14 additions and 2 deletions

View File

@ -362,6 +362,13 @@ void fill_default_config()
} }
} // namespace } // namespace
namespace {
void print_version(std::ostream& out)
{
out << get_config()->server_name << std::endl;
}
} // namespace
namespace { namespace {
void print_usage(std::ostream& out) void print_usage(std::ostream& out)
{ {
@ -498,7 +505,8 @@ void print_help(std::ostream& out)
<< " --conf=<PATH> Load configuration from PATH.\n" << " --conf=<PATH> Load configuration from PATH.\n"
<< " Default: " << " Default: "
<< get_config()->conf_path << "\n" << get_config()->conf_path << "\n"
<< " -h, --help Print this help.\n" << " -v, --version Print version and exit.\n"
<< " -h, --help Print this help and exit.\n"
<< std::endl; << std::endl;
} }
} // namespace } // namespace
@ -523,6 +531,7 @@ int main(int argc, char **argv)
{"workers", required_argument, 0, 'n' }, {"workers", required_argument, 0, 'n' },
{"client-proxy", no_argument, 0, 'p' }, {"client-proxy", no_argument, 0, 'p' },
{"spdy-proxy", no_argument, 0, 's' }, {"spdy-proxy", no_argument, 0, 's' },
{"version", no_argument, 0, 'v' },
{"add-x-forwarded-for", no_argument, &flag, 1 }, {"add-x-forwarded-for", no_argument, &flag, 1 },
{"frontend-spdy-read-timeout", required_argument, &flag, 2 }, {"frontend-spdy-read-timeout", required_argument, &flag, 2 },
{"frontend-read-timeout", required_argument, &flag, 3 }, {"frontend-read-timeout", required_argument, &flag, 3 },
@ -545,7 +554,7 @@ int main(int argc, char **argv)
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "DL:b:c:f:hkn:ps", long_options, int c = getopt_long(argc, argv, "DL:b:c:f:hkn:psv", long_options,
&option_index); &option_index);
if(c == -1) { if(c == -1) {
break; break;
@ -582,6 +591,9 @@ int main(int argc, char **argv)
case 's': case 's':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_SPDY_PROXY, "yes")); cmdcfgs.push_back(std::make_pair(SHRPX_OPT_SPDY_PROXY, "yes"));
break; break;
case 'v':
print_version(std::cout);
exit(EXIT_SUCCESS);
case '?': case '?':
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case 0: case 0: