Skip to content

Commit 119e01a

Browse files
committed
fix core: print usage and help correctly in DaemonRun, allow --config-vars
* Fixed an issue where required options would not allow to call the service binary with `-h` flag. * Allowed passing `--config-vars` option to service binary as an alternative to `--config_vars`. commit_hash:de7861a072966d468ddc6d9fdce820992050989f
1 parent cb1c273 commit 119e01a

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

core/src/utils/daemon_run.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ std::optional<std::string> ToOptional(const Value& val) {
2525
}
2626
}
2727

28+
constexpr std::string_view kUsage = "USAGE: service --config PATH_TO_CONFIG [--config_vars PATH_TO_CONFIG_VARS]";
29+
2830
} // namespace
2931

3032
boost::program_options::options_description BaseRunOptions() {
@@ -35,8 +37,8 @@ boost::program_options::options_description BaseRunOptions() {
3537
("help,h", "produce this help message")
3638
("print-config-schema", "print config.yaml YAML Schema")
3739
("print-dynamic-config-defaults", "print JSON object with dynamic config defaults")
38-
("config_vars", po::value<std::string>(), "path to config_vars.yaml; if set, config_vars in config.yaml are ignored")
39-
("config_vars_override", po::value<std::string>(), "path to an additional config_vars.yaml, which overrides vars of config_vars.yaml")
40+
("config-vars,config_vars", po::value<std::string>(), "path to config_vars.yaml; if set, config_vars in config.yaml are ignored")
41+
("config-vars-override,config_vars_override", po::value<std::string>(), "path to an additional config_vars.yaml, which overrides vars of config_vars.yaml")
4042
;
4143
// clang-format on
4244
return desc;
@@ -52,15 +54,21 @@ int DaemonMain(const int argc, const char* const argv[], const components::Compo
5254
po::store(po::parse_command_line(argc, argv, desc), vm);
5355
po::notify(vm);
5456
} catch (const std::exception& ex) {
55-
const auto msg = fmt::format("{}\n", ex.what());
57+
if (vm.count("help")) {
58+
std::ostringstream oss;
59+
oss << kUsage << "\n\n" << desc << '\n';
60+
std::fputs(oss.str().c_str(), stdout);
61+
return 0;
62+
}
63+
const auto msg = fmt::format("{}\n\n{}\nPass -h for full options description\n", ex.what(), kUsage);
5664
std::fputs(msg.c_str(), stderr);
5765
return 1;
5866
}
5967

6068
if (vm.count("help")) {
6169
std::ostringstream oss;
62-
oss << desc << '\n';
63-
std::fputs(oss.str().c_str(), stderr);
70+
oss << kUsage << "\n\n" << desc << '\n';
71+
std::fputs(oss.str().c_str(), stdout);
6472
return 0;
6573
}
6674

libraries/easy/src/easy.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,13 @@ HttpBase::~HttpBase() {
143143
;
144144
// clang-format on
145145

146-
po::store(po::parse_command_line(argc_, argv_, desc), vm);
147-
po::notify(vm);
146+
try {
147+
po::store(po::parse_command_line(argc_, argv_, desc), vm);
148+
po::notify(vm);
149+
} catch (const std::exception& ex) {
150+
std::cerr << ex.what() << '\n' << desc << '\n';
151+
return;
152+
}
148153

149154
if (vm.count("help")) {
150155
std::cerr << desc << '\n';

0 commit comments

Comments
 (0)