Skip to content

Commit

Permalink
prefix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Sep 16, 2024
1 parent a9cd8cb commit 2492ea7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/cpp/util/core/prefix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ 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;

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) {
Expand Down

0 comments on commit 2492ea7

Please sign in to comment.