catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
develroot / tools / VersionMain.cpp
// Copyright (c) 2026 Progmasoft.
// SPDX-License-Identifier: LGPL-3.0-or-later
// 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 <iostream>
#include <string>
#include <string_view>
#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|<version>]\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);
}