summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-26 03:38:30 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-26 03:38:30 -0600
commitca78cc8d66498cccf54ed26d5318f09362859ba7 (patch)
tree3866191d28f1d02c64f187935d8f0aa3bcc6b8a3 /hscript
parent9cb6b1ed8523c39acc3d3096c1154152ea7174e7 (diff)
downloadhorizon-ca78cc8d66498cccf54ed26d5318f09362859ba7.tar.gz
horizon-ca78cc8d66498cccf54ed26d5318f09362859ba7.tar.bz2
horizon-ca78cc8d66498cccf54ed26d5318f09362859ba7.tar.xz
horizon-ca78cc8d66498cccf54ed26d5318f09362859ba7.zip
hscript: Add introspection support for Script class
Diffstat (limited to 'hscript')
-rw-r--r--hscript/script.cc76
-rw-r--r--hscript/script.hh22
2 files changed, 98 insertions, 0 deletions
diff --git a/hscript/script.cc b/hscript/script.cc
index 10dfe6b..0bc6b8a 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -317,4 +317,80 @@ const Script *Script::load(std::istream &sstream,
#undef PARSER_ERROR
}
+/* LCOV_EXCL_START */
+const Keys::Key *Script::getOneValue(std::string name) const {
+ if(name == "network") {
+ return this->internal->network.get();
+ } else if(name == "hostname") {
+ return this->internal->hostname.get();
+ } else if(name == "arch") {
+ return this->internal->arch.get();
+ } else if(name == "rootpw") {
+ return this->internal->rootpw.get();
+ } else if(name == "language") {
+ return this->internal->lang.get();
+ } else if(name == "keymap") {
+ return this->internal->keymap.get();
+ } else if(name == "firmware") {
+#ifdef NON_LIBRE_FIRMWARE
+ return this->internal->firmware.get();
+#else /* !NON_LIBRE_FIRMWARE */
+ return nullptr;
+#endif /* NON_LIBRE_FIRMWARE */
+ } else if(name == "timezone") {
+ return this->internal->tzone.get();
+ }
+
+ assert("Unknown key given to getOneValue." == nullptr);
+ return nullptr;
+}
+
+const std::vector<Keys::Key *> Script::getValues(std::string name) const {
+ std::vector<Keys::Key *> values;
+
+ if(name == "netaddress") {
+ for(auto &addr : this->internal->addresses) values.push_back(addr.get());
+ } else if(name == "nameserver") {
+ for(auto &ns : this->internal->nses) values.push_back(ns.get());
+ } else if(name == "netssid") {
+ for(auto &ssid : this->internal->ssids) values.push_back(ssid.get());
+ } else if(name == "pkginstall") {
+ /* XXX */
+ } else if(name == "repository") {
+ for(auto &repo : this->internal->repos) values.push_back(repo.get());
+ } else if(name == "signing_key") {
+ for(auto &key : this->internal->repo_keys) values.push_back(key.get());
+ } else if(name == "username" || name == "useralias" || name == "userpw" ||
+ name == "usericon" || name == "usergroups") {
+ /* XXX */
+ } else if(name == "diskid") {
+ for(auto &id : this->internal->diskids) values.push_back(id.get());
+ } else if(name == "disklabel") {
+ for(auto &label : this->internal->disklabels) values.push_back(label.get());
+ } else if(name == "partition") {
+ for(auto &part : this->internal->partitions) values.push_back(part.get());
+ } else if(name == "lvm_pv") {
+ for(auto &pv : this->internal->lvm_pvs) values.push_back(pv.get());
+ } else if(name == "lvm_vg") {
+ for(auto &vg : this->internal->lvm_vgs) values.push_back(vg.get());
+ } else if(name == "lvm_lv") {
+ for(auto &lv : this->internal->lvm_lvs) values.push_back(lv.get());
+ } else if(name == "encrypt") {
+ /* XXX */
+ } else if(name == "fs") {
+ for(auto &fs : this->internal->fses) values.push_back(fs.get());
+ } else if(name == "mount") {
+ for(auto &mnt : this->internal->mounts) values.push_back(mnt.get());
+ } else {
+ assert("Unknown key given to getValues." == nullptr);
+ }
+
+ return values;
+}
+/* LCOV_EXCL_STOP */
+
+ScriptOptions Script::options() const {
+ return this->opts;
+}
+
}
diff --git a/hscript/script.hh b/hscript/script.hh
index 9fd186a..8cf6c2a 100644
--- a/hscript/script.hh
+++ b/hscript/script.hh
@@ -20,6 +20,12 @@
namespace Horizon {
+namespace Keys {
+
+class Key;
+
+}
+
/**** Script option flags ****/
enum ScriptOptionFlags {
@@ -74,6 +80,22 @@ public:
/*! Executes the HorizonScript. */
bool execute() const;
+ /*! Retrieve the value of a specified key in this HorizonScript.
+ * @param name The name of the key to retrieve.
+ * @return The key object, if one exists. nullptr if the key has not been
+ * specified.
+ */
+ const Keys::Key *getOneValue(std::string name) const;
+
+ /*! Retrieve all values for a specified key in this HorizonScript.
+ * @param name The name of the key to retrieve.
+ * @return A std::vector of the key objects. The vector may be empty if
+ * no values exist for the specified key.
+ */
+ const std::vector<Keys::Key *> getValues(std::string name) const;
+
+ /*! Retrieve the options set for this HorizonScript object. */
+ ScriptOptions options() const;
private:
struct ScriptPrivate;
/*! Internal data. */