Skip to content

Commit 6e75517

Browse files
committed
Use more consistent option descriptions
1 parent e8c8eba commit 6e75517

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/getopts.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ bool parse(QCoreApplication &app) {
1111
p.addHelpOption();
1212
p.addVersionOption();
1313

14+
const auto make_descr = [](const std::ranges::range auto &opts) { return std::ranges::fold_left(opts, std::string(), [](const auto &l, const auto &r) { return l + " " + r; }); };
1415
// must be in the same order as the enum
1516
constexpr std::array frontend_opts = {"auto", "gui", "immediate", "notify", "clipboard", "stdout"};
16-
const std::string frontends_descr = std::ranges::fold_left(frontend_opts, std::string(), [](const auto &l, const auto &r) { return l + " " + r; });
17+
const std::string frontends_descr = make_descr(frontend_opts);
18+
constexpr std::array auto_quit_opts = {"never", "first", "all"};
19+
const std::string auto_quit_descr = make_descr(auto_quit_opts);
1720

1821
QCommandLineOption frameless_opt(QStringList() << "b"
1922
<< "frameless",
@@ -42,18 +45,17 @@ bool parse(QCoreApplication &app) {
4245
"Keep the window on top of other windows.");
4346
QCommandLineOption auto_quit_opt(QStringList() << "x"
4447
<< "auto-quit",
45-
"The amount of drags after which the program should automatically close. Must be one of {never, first, all (default)}",
48+
"The amount of drags after which the program should automatically close. Must be one of:" + QString::fromStdString(auto_quit_descr) + " (all is default)",
4649
"behaviour");
4750

4851
p.addOptions({frameless_opt, cursor_opt, frontend_opt, intercept_opt, keep_opt, persistent_opt, remote_opt, ontop_opt, auto_quit_opt});
4952
p.process(app);
5053

5154
if (p.isSet(auto_quit_opt)) {
5255
const auto opt = p.value(auto_quit_opt);
53-
constexpr std::array str_repr = {"never", "first", "all"};
54-
int choice = std::ranges::find(str_repr, opt.toStdString()) - str_repr.cbegin();
56+
int choice = std::ranges::find(auto_quit_opts, opt.toStdString()) - auto_quit_opts.cbegin();
5557
if (static_cast<Settings::AutoQuitBehavior>(choice) > Settings::AutoQuitBehavior::All) {
56-
std::cerr << "auto-quit needs to be one of {never,first,all}" << std::endl;
58+
std::cerr << "auto-quit needs to be one of:" << auto_quit_descr << std::endl;
5759
return false;
5860
}
5961
Settings::get()->auto_quit_behavior = static_cast<Settings::AutoQuitBehavior>(choice);

0 commit comments

Comments
 (0)