commit 5392eafa8ff963fb7d62e7373b808746eabcb6df
parent 15381801ff03f62dfc528a5bd1ee07b7e1833281
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 9 Dec 2024 21:33:00 +0100
add Discord as possible output format
Diffstat:
1 file changed, 59 insertions(+), 20 deletions(-)
diff --git a/source/commandlineGenerator/commandlineGenerator.cpp b/source/commandlineGenerator/commandlineGenerator.cpp
@@ -11,6 +11,12 @@ using LinesPerKey = std::map<std::string, Lines>;
namespace
{
+ enum class Format
+ {
+ Txt,
+ Discord
+ };
+
std::string& trim(std::string& _line)
{
auto needsTrim = [](const char _c) -> bool
@@ -156,11 +162,14 @@ namespace
}
return out;
}
- bool writeProduct(std::ofstream& _out, const std::string& _product, const Lines& _lines)
+ bool writeProduct(std::ofstream& _out, const std::string& _product, const Lines& _lines, const bool _needsSpace)
{
if (_lines.empty())
return false;
+ if (_needsSpace)
+ _out << '\n';
+
if (!_product.empty())
{
_out << _product << ":\n";
@@ -197,6 +206,23 @@ int main(const int _argc, char* _argv[])
if (outPath.back() != '/' && outPath.back() != '\\')
outPath.push_back('/');
+ auto f = cmdLine.get("f");
+
+ auto format = Format::Txt;
+
+ if (!f.empty())
+ {
+ if (f == "discord")
+ {
+ format = Format::Discord;
+ }
+ else
+ {
+ std::cout << "Unknown format '" << f << "'\n";
+ return -1;
+ }
+ }
+
std::ifstream file(inFile);
if (!file.is_open())
@@ -276,6 +302,15 @@ int main(const int _argc, char* _argv[])
std::set<std::string> globalProducts = { "DSP", "Framework", "Patch Manager" };
std::set<std::string> localProducts = { "Osirus", "OsTIrus", "Xenia", "Vavra", "NodalRed2x" };
+ auto formatHeader = [format](const std::string & _header)
+ {
+ if (format == Format::Discord)
+ {
+ return "**" + _header + "**";
+ }
+ return _header;
+ };
+
for (auto& itVersion : productPerVersion)
{
const auto& version = itVersion.first;
@@ -320,18 +355,23 @@ int main(const int _argc, char* _argv[])
}
if (!product.empty())
- outFile << product << ' ';
-
- outFile << "Version " << version << '\n';
+ outFile << formatHeader(product + " Version " + version) << '\n';
+ else
+ outFile << formatHeader("Version " + version) << '\n';
outFile << '\n';
+ if (format == Format::Discord)
+ outFile << "```\n";
+
+ bool needsSpace = false;
+
for (const auto& global : globals)
- {
- if (writeProduct(outFile, global.first, global.second))
- outFile << '\n';
- }
+ needsSpace |= writeProduct(outFile, global.first, global.second, needsSpace);
+
+ writeProduct(outFile, product, itProduct.second, needsSpace);
- writeProduct(outFile, product, itProduct.second);
+ if (format == Format::Discord)
+ outFile << "```\n";
}
}
@@ -344,23 +384,22 @@ int main(const int _argc, char* _argv[])
std::cout << "Failed to create output file '" << outName << '\n';
return -1;
}
- outFile << "Version " << version << '\n';
+ outFile << formatHeader("Version " + version) << '\n';
outFile << '\n';
- for (const auto& global : globals)
- {
- if (writeProduct(outFile, global.first, global.second))
- outFile << '\n';
- }
+
+ if (format == Format::Discord)
+ outFile << "```\n";
bool needsSpace = false;
+ for (const auto& global : globals)
+ needsSpace |= writeProduct(outFile, global.first, global.second, needsSpace);
+
for (const auto& local : locals)
- {
- if (needsSpace)
- outFile << '\n';
+ needsSpace |= writeProduct(outFile, local.first, local.second, needsSpace);
- needsSpace = writeProduct(outFile, local.first, local.second);
- }
+ if (format == Format::Discord)
+ outFile << "```\n";
}
return 0;
}