From 2492ea78f55c42d53e57c65c53187c893c3ec496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berke=20Kocao=C4=9Flu?= Date: Mon, 16 Sep 2024 17:21:57 +0300 Subject: [PATCH] prefix: refactor --- src/cpp/util/core/prefix.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cpp/util/core/prefix.cpp b/src/cpp/util/core/prefix.cpp index d5812d4e..1245ef85 100644 --- a/src/cpp/util/core/prefix.cpp +++ b/src/cpp/util/core/prefix.cpp @@ -22,14 +22,18 @@ public: \ return m_##NAME; \ } -#define OPT(NAME) lyra::opt(m_##NAME) +#define OPT() \ + X_OPT(bool, prefix_time, false, t, time, "current time") \ + X_OPT(bool, prefix_delta, false, d, delta, "delta time") \ + X_OPT(bool, prefix_line, false, l, line, "line number") DEFINE_EXEC_INFO() class Options { - DECLARE_FIELD(bool, prefix_time, false); - DECLARE_FIELD(bool, prefix_delta, false); - DECLARE_FIELD(bool, prefix_line, false); +#define X_OPT(X_TYPE, X_NAME, X_DEFAULT, X_SHORT, X_LONG, X_DESC) \ + DECLARE_FIELD(X_TYPE, X_NAME, X_DEFAULT); + OPT() +#undef X_OPT public: Options() = delete; @@ -37,11 +41,11 @@ class Options { Options(int argc, char** argv) { bool help = false; +#define X_OPT(X_TYPE, X_NAME, X_DEFAULT, X_SHORT, X_LONG, X_DESC) \ + | lyra::opt(m_##X_NAME)["-" #X_SHORT]["--" #X_LONG]("prefix lines with " X_DESC) auto cli = lyra::cli() | - lyra::help(help).description("Prefix lines with selected attributes.") | - OPT(prefix_time)["-t"]["--time"]("prefix lines with current time") | - OPT(prefix_delta)["-d"]["--delta"]("prefix lines with delta time") | - OPT(prefix_line)["-l"]["--line"]("prefix lines with line number"); + lyra::help(help).description("Prefix lines with selected attributes.") OPT(); +#undef X_OPT auto args = cli.parse({ argc, argv }); if (!args) {