summaryrefslogtreecommitdiff
path: root/image/creator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'image/creator.cc')
-rw-r--r--image/creator.cc38
1 files changed, 33 insertions, 5 deletions
diff --git a/image/creator.cc b/image/creator.cc
index 3b145de..ce688fa 100644
--- a/image/creator.cc
+++ b/image/creator.cc
@@ -13,19 +13,26 @@
#include <boost/program_options.hpp>
#include <cstdlib> /* EXIT_* */
#include <string>
+#include "backends/backends.hh"
#include "hscript/script.hh"
#include "util/output.hh"
-bool pretty = true;
+bool pretty = true; /*! Controls ASCII colour output */
+
#define DESCR_TEXT "Usage: hscript-image [OPTION]... [INSTALLFILE]\n"\
"Write an operating system image configured per INSTALLFILE"
+/*! Text used at the top of usage output */
+
+/*! Entry-point for the image creation utility. */
int main(int argc, char *argv[]) {
using namespace boost::program_options;
bool needs_help{}, disable_pretty{};
int exit_code = EXIT_SUCCESS;
- std::string if_path{"/etc/horizon/installfile"}, ir_dir{"/target"};
+ std::string if_path{"/etc/horizon/installfile"}, ir_dir{"/target"}, type_code{"tar"};
+ Horizon::ScriptOptions opts;
+ Horizon::Script *my_script;
options_description ui{DESCR_TEXT};
options_description general{"General options"};
@@ -71,17 +78,36 @@ int main(int argc, char *argv[]) {
/* -n/--no-colour, or logging to file */
if(disable_pretty || !isatty(1)) {
pretty = false;
+ } else {
+ opts.set(Horizon::Pretty);
+ }
+
+ if(!vm["type"].empty()) {
+ type_code = vm["type"].as<std::string>();
+ }
+
+ if(type_code == "list") {
+ std::cout << "Type codes known by this build of Image Creation:"
+ << std::endl << std::endl;
+ for(auto &backend : Horizon::Image::known_backends) {
+ std::cout << std::setw(10) << std::left << backend.type_code
+ << backend.description << std::endl;
+ }
+ return EXIT_SUCCESS;
}
if(!vm["installfile"].empty()) {
if_path = vm["installfile"].as<std::string>();
}
- Horizon::Script *my_script;
+ opts.set(Horizon::InstallEnvironment);
+ opts.set(Horizon::ImageOnly);
+
if(if_path == "-") {
- my_script = Horizon::Script::load(std::cin);
+ /* Unix-style stdin specification */
+ my_script = Horizon::Script::load(std::cin, opts);
} else {
- my_script = Horizon::Script::load(if_path);
+ my_script = Horizon::Script::load(if_path, opts);
}
/* if an error occurred during parsing, bail out now */
@@ -93,6 +119,8 @@ int main(int argc, char *argv[]) {
my_script->setTargetDirectory(vm["ir-dir"].as<std::string>());
}
+ my_script->execute();
+
delete my_script;
return exit_code;
}