From 8ab826bf68326239d0aaa319440d85fe685a4e21 Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 7 Oct 2021 21:32:42 +0200 Subject: [PATCH] Move a condition from Target.hpp to main.cpp and add a new Yerbacon::exit function --- src/headers/Yerbacon.hpp | 9 +++++++++ src/headers/transpiler/Target.hpp | 8 +------- src/main.cpp | 8 +++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index aca5457..094b545 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -22,9 +22,18 @@ #include #include #include +#include +#include namespace Yerbacon { consteval const char* getVersion() noexcept { return YBCON_VERSION; } + inline void exit(const std::initializer_list reason) { + std::for_each(reason.begin(), reason.end(), [](const char* current_string){ + std::cout << current_string; + }); + std::cout << std::endl; + std::exit(EXIT_FAILURE); + } class Exception: public std::exception { std::string exceptionCause; public: diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index 0fa275e..dee17a4 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -118,13 +118,7 @@ shared_ptr Target::forName(string_view name, const bool newLines = true) case PY: ADDTARGET(PY_HPP); break; #endif case NONE: - default: { - if (not name.empty()) { - cout << '"' << (char) toupper(name.at(1)); - name.remove_prefix(2); cout << name << "\" is not a valid target." << endl; - } else cout << "No target was provided." << endl; - exit(0); - } + default: Yerbacon::exit({"\"", string(1, (char) toupper(name.at(1))).data(), name.substr(2).data(), "\" is not a valid target."}); } #undef ADDTARGET if (not newLines and not target->supportsOneLine()) { diff --git a/src/main.cpp b/src/main.cpp index a3b5c36..361f78f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,15 +21,13 @@ int main(int argc, char* argv[]) { else if (currentArg == ArgumentShort("printresult")) printResult = true; else if (currentArg == ArgumentAssignable("target")) { const string_view value = ArgumentAssignable::getValueFor(currentArg); - if (!value.empty()) (target = '.') += value; + if (not value.empty()) (target = '.') += value; + else Yerbacon::exit({"No target was provided."}); } else if (currentArg == Argument("parallel")) parallel = true; else if (currentArg == Argument("newlinesoff")) newLines = false; else if (currentArg.ends_with(".ybcon")) files.insert(currentArg); - else { - cout << '"' << currentArg << "\" is not a valid argument." << endl; - exit(EXIT_FAILURE); - } + else Yerbacon::exit({"\"", currentArg.data(), "\" is not a valid argument."}); } const auto compile = [&target, &newLines](string_view name) -> string { string transpiledString = transpile(parseString(getFileContent(name.data())), target, newLines);