From 048db07ca91505ccfcb98e29ed6868f1aa64a514 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 27 Jan 2015 21:19:49 +0100 Subject: wrote initialization section for program logic, which is probably not complete yet. also improved output path handling. --- src/cli/Main.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index 73c46ba..24c0ec7 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -29,11 +29,23 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + const size_t ERROR_IN_COMMAND_LINE = 1; const size_t SUCCESS = 0; const size_t ERROR_UNHANDLED_EXCEPTION = 2; namespace po = boost::program_options; +namespace o = ousia; int main(int argc, char **argv) { @@ -83,28 +95,54 @@ int main(int argc, char **argv) std::cerr << desc << std::endl; return ERROR_IN_COMMAND_LINE; } - - if(!vm.count("output")){ - // TODO: Handle this better. + + // prepare output path + if (!vm.count("output")) { outputPath = inputPath; - if(outputPath.find(".oxd") != std::string::npos){ - outputPath.erase(outputPath.end()-3, outputPath.end()); + auto pos = outputPath.find_last_of('.'); + if (pos != std::string::npos) { + outputPath.erase(outputPath.begin() + pos + 1, outputPath.end()); outputPath += format; + std::cout << "Using " << outputPath << " as output path." + << std::endl; } } - // TODO: Program logic. - std::cout << "input : " << vm["input"].as() << std::endl; - std::cout << "output : " << outputPath << std::endl; - std::cout << "format : " << vm["format"].as() << std::endl; - if(vm.count("include")){ - std::vector includes = vm["include"].as>(); - std::cout << "includes : "; - for(auto& i : includes){ - std::cout << i << ", "; + // initialize global instances. + o::TerminalLogger logger{std::cerr, true}; + o::Manager manager; + o::Registry registry; + o::Rooted project{new o::Project(manager)}; + o::FileLocator fileLocator; + + // fill registry + registry.registerDefaultExtensions(); + o::XmlParser xmlParser; + registry.registerParser( + {"text/vnd.ousia.oxm", "text/vnd.ousia.oxd"}, + // TODO: Why don't we have domains here? + {&o::RttiTypes::Document, &o::RttiTypes::Typesystem}, &xmlParser); + registry.registerResourceLocator(&fileLocator); + + // register search paths + fileLocator.addDefaultSearchPaths(); + // in user includes we allow every kind of resource. + if (vm.count("include")) { + std::vector includes = + vm["include"].as>(); + for (auto &i : includes) { + fileLocator.addSearchPath(i, o::ResourceType::UNKNOWN); + fileLocator.addSearchPath(i, o::ResourceType::DOMAIN_DESC); + fileLocator.addSearchPath(i, o::ResourceType::TYPESYSTEM); + fileLocator.addSearchPath(i, o::ResourceType::DOCUMENT); + fileLocator.addSearchPath(i, o::ResourceType::ATTRIBUTES); + fileLocator.addSearchPath(i, o::ResourceType::STYLESHEET); + fileLocator.addSearchPath(i, o::ResourceType::SCRIPT); + fileLocator.addSearchPath(i, o::ResourceType::DATA); } - std::cout << std::endl; } + // now all preparation is done and we can parse. TODO: But how? + return SUCCESS; } -- cgit v1.2.3 From 1ba148f4950490e76dfcd09c393e4ff28e80efc4 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 27 Jan 2015 21:32:11 +0100 Subject: added input as positional argument. --- src/cli/Main.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cli/Main.cpp b/src/cli/Main.cpp index 24c0ec7..05d89ca 100644 --- a/src/cli/Main.cpp +++ b/src/cli/Main.cpp @@ -50,7 +50,8 @@ namespace o = ousia; int main(int argc, char **argv) { // Program options - po::options_description desc("Options"); + po::options_description desc( + "Program usage\n./ousia [optional options] <-F format> \nProgram options"); std::string inputPath; std::string outputPath; std::string format; @@ -70,11 +71,19 @@ int main(int argc, char **argv) "The output file name. Per default the input file name will be used.")( "format,F", po::value(&format)->required(), "The output format that shall be produced."); - + // "input" should be a positional option, such that we can write: + // ./ousia [some options] + // without having to use -i or I + po::positional_options_description positional; + positional.add("input", 1); po::variables_map vm; try { // try to read the values for each option to the variable map. - po::store(po::parse_command_line(argc, argv, desc), vm); + po::store(po::command_line_parser(argc, argv) + .options(desc) + .positional(positional) + .run(), + vm); // first check the help option. if (vm.count("help")) { @@ -108,6 +117,20 @@ int main(int argc, char **argv) } } + // TODO: REMOVE diagnostic code. + std::cout << "input : " << vm["input"].as() << std::endl; + std::cout << "output : " << outputPath << std::endl; + std::cout << "format : " << vm["format"].as() << std::endl; + if (vm.count("include")) { + std::vector includes = + vm["include"].as>(); + std::cout << "includes : "; + for (auto &i : includes) { + std::cout << i << ", "; + } + std::cout << std::endl; + } + // initialize global instances. o::TerminalLogger logger{std::cerr, true}; o::Manager manager; -- cgit v1.2.3