// Copyright (c) 2026 Progmasoft. // SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0 // bazelisk run //tools:version prints the current version // bazelisk run //tools:version -- --next moves to the next patch release // bazelisk run //tools:version -- 0.4.0 moves to that version // // Moving writes every place that states the version, and the amalgamation. #include #include #include #include "tools/Amalgamation.hpp" #include "tools/Repository.hpp" #include "tools/Versions.hpp" int main(int argc, char **argv) { using namespace Progmasoft::Catch3::Tools; if (argc > 2) { std::cerr << "usage: bazelisk run //tools:version [-- --next|]\n"; return 2; } const auto root = RepositoryRoot(); if (!root) { std::cerr << "run this tool with bazelisk run\n"; return 2; } Problems problems; const auto current = CurrentVersion(*root, problems); if (!current) { return Finish(problems); } if (argc == 1) { std::cout << *current << '\n'; return 0; } const std::string_view argument{ argv[1] }; const auto parsed = argument == "--next" ? NextPatch(*current) : ParseVersion(argument); if (!parsed) { std::cerr << (argument == "--next" ? "the current version is not a release version: " + *current : "not a version MAJOR.MINOR.PATCH: " + std::string{ argument }) << '\n'; return 2; } const auto version = FormatVersion(*parsed); // The sources have to make a distribution before anything is changed. (void)GenerateAmalgamation(*root, problems); if (problems.empty()) { SetVersion(*root, version, problems); } if (problems.empty()) { const auto amalgamation = GenerateAmalgamation(*root, problems); if (problems.empty()) { WriteAmalgamation(*root, amalgamation, problems); } } if (problems.empty()) { std::cout << *current << " -> " << version << '\n'; } return Finish(problems); }