Move a condition from Target.hpp to main.cpp and add a new Yerbacon::exit function

This commit is contained in:
Username404 2021-10-07 21:32:42 +02:00
parent 7b1987f81b
commit 8ab826bf68
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 13 additions and 12 deletions

View File

@ -22,9 +22,18 @@
#include <string_view>
#include <string>
#include <optional>
#include <algorithm>
#include <iostream>
namespace Yerbacon {
consteval const char* getVersion() noexcept { return YBCON_VERSION; }
inline void exit(const std::initializer_list<const char*> 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:

View File

@ -118,13 +118,7 @@ shared_ptr<Target> 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()) {

View File

@ -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);