From cfa6b082eaa4a02f34576cbd5a55e3c46f04acdd Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 24 Jun 2022 20:33:48 -1000 Subject: refactor(help): move version to constexpr --- src/cli.cc | 2 +- src/help.cc | 30 +++++++++++++++++++++++------- src/help.hh | 17 +++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/cli.cc b/src/cli.cc index b1f4eb4..573b9a9 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -72,7 +72,7 @@ auto cli::look() -> int { std::cout << cait::help_message() << '\n'; } break; case cait::utility::hash("--version"): { - std::cout << VERSION << '\n'; + std::cout << version::whole() << '\n'; } break; default: { std::string cait_file_name = this->option("-f")->value_or("build.cait"); diff --git a/src/help.cc b/src/help.cc index 18853e1..2271e9f 100644 --- a/src/help.cc +++ b/src/help.cc @@ -32,13 +32,29 @@ auto help_message() -> std::string { "manual).\n" "\n" "options:\n" - " --version print cait version (\"" VERSION "\")\n" - " -v, --verbose show all command lines while building\n" - "\n" - " -C DIR change to DIR before doing anything else\n" - " -f FILE specify input build file [default=build.cait]\n" - "\n" - " -j N run N jobs in parallel (0 means infinity) [default=" + " --version print cait version (\"" + + version::whole() + + "\")\n" + " -v, --verbose " + "show all command " + "lines while " + "building\n" + "\n" + " -C DIR " + "change to DIR " + "before doing " + "anything else\n" + " -f FILE " + "specify input " + "build file " + "[default=build." + "cait]\n" + "\n" + " -j N run N " + "jobs in parallel " + "(0 means " + "infinity) " + "[default=" << std::thread::hardware_concurrency() + 2 << " on this system]\n" " -k N keep going until N jobs fail (0 means infinity) " diff --git a/src/help.hh b/src/help.hh index 37afb58..88517da 100644 --- a/src/help.hh +++ b/src/help.hh @@ -21,13 +21,22 @@ #include -#define VERSION_MAJOR "0" -#define VERSION_MINOR "1" -#define VERSION_PATCH "0" -#define VERSION VERSION_MAJOR "." VERSION_MINOR "." VERSION_PATCH +#define CAIT_TO_STRING(x) #x +#define CAIT_STR(x) CAIT_TO_STRING(x) namespace cait { +namespace version { + +constexpr unsigned int major = 0; +constexpr unsigned int minor = 1; +constexpr unsigned int patch = 0; +constexpr auto whole() -> std::string { + return CAIT_STR(major) "." CAIT_STR(minor) "." CAIT_STR(patch); +} + +} // namespace version + auto help_message() -> std::string; } // namespace cait -- cgit v1.2.3