From 72badbe8db656358dcb7f7d05e00578acdffab96 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 8 Oct 2019 20:10:52 -0500 Subject: hscript: Ensure required keys are present --- hscript/script.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hscript/script.cc b/hscript/script.cc index 1bb2176..93d8cb4 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -121,9 +121,13 @@ struct Script::ScriptPrivate { } else if(key_name == "rootpw") { /*! TODO: implement */ return false; + } else if(key_name == "mount") { + /*! TODO: implement */ + return false; } else { return false; } +#undef DUPLICATE_ERROR } }; @@ -232,6 +236,30 @@ const Script *Script::load(std::istream &sstream, const ScriptOptions opts) { errors++; } + /* Ensure no required keys are missing. */ +#define MISSING_ERROR(key) \ + output_error("installfile:" + std::to_string(lineno),\ + "expected value for key '" + key + "'",\ + "this key is required", (opts.test(Pretty)));\ + errors++; + + if(!the_script->internal->network) { + MISSING_ERROR(std::string("network")) + } + if(!the_script->internal->hostname) { + MISSING_ERROR(std::string("hostname")) + } + if(the_script->internal->packages.size() == 0) { + MISSING_ERROR(std::string("pkginstall")) + } + if(!the_script->internal->rootpw) { + MISSING_ERROR(std::string("rootpw")) + } + if(the_script->internal->mounts.size() == 0) { + MISSING_ERROR(std::string("mount")) + } +#undef MISSING_ERROR + output_message("parser", "0", "installfile", std::to_string(errors) + " error(s), " + std::to_string(warnings) + " warning(s).", -- cgit v1.2.3-60-g2f50