From 6435f9be3974fdce9959fd7ed3cc9ed5673d6f1f Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 21 Dec 2022 15:30:27 +0100 Subject: [PATCH] Started functionality on run_project() It reads and extracts the config for now. The plan for the actual files are yet to be made. Yes, the *plan* hasn't been made yet. Don't remind me. --- src/ceev.cc | 25 +++++++++++++++++++++++-- src/ceev.h | 5 +++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ceev.cc b/src/ceev.cc index b6527fd..9309b78 100644 --- a/src/ceev.cc +++ b/src/ceev.cc @@ -62,16 +62,18 @@ int create_fs(std::deque args) { std::cout << "Project name [" << directory << "]: "; std::getline(std::cin, project_name); if (project_name == "") project_name = directory; - config << "name = " << project_name << '\n'; + config << "name=" << project_name << '\n'; std::string version; std::cout << "Version [0.0.1]: "; std::getline(std::cin, version); if (version == "") version = "0.0.1"; - config << "version = " << version << '\n'; + config << "version=" << version << '\n'; std::string author; std::cout << "Author: "; std::getline(std::cin, author); if (author == "") author = "Unknown"; + config << "author=" << author << '\n'; + config.close(); return 0; } int build_project(std::deque args) { @@ -79,6 +81,25 @@ int build_project(std::deque args) { return 0; } int run_project(std::deque args) { + std::ifstream config(".ceev/config"); + if (!config) { + std::cerr << bg_red(bold("ERROR")) << ": Could not open config\n"; + std::cerr << "Run `ceev init' to create a new project." << std::endl; + return 1; + } + std::string line; + while (std::getline(config, line)) { + std::istringstream iss(line); + struct config_data data; + std::string key; + if (!std::getline(iss, key, '=')) continue; + std::string value; + if (!std::getline(iss, value)) continue; + if (key == "name") data.name = value; + if (key == "version") data.version = value; + if (key == "author") data.author = value; + } + config.close(); std::cout << "Running project..." << std::endl; return 0; } diff --git a/src/ceev.h b/src/ceev.h index 7bbc6d3..23839de 100644 --- a/src/ceev.h +++ b/src/ceev.h @@ -11,6 +11,11 @@ namespace fs = std::filesystem; +struct config_data { + std::string name = ""; + std::string version = ""; + std::string author = ""; +}; int usage(); int show_help(); int create_fs(std::deque args);