Started work on ceev init, and planned ceev clean.

Also did some cleanup on show_help(), by adding a simple color library.
Not the cleanest, but the code is more readable now, and that's more
important.
master
Ruben 2022-12-21 09:49:46 +01:00
parent fb93394da6
commit b742db9cda
No known key found for this signature in database
GPG Key ID: F6DAAC2742760162
5 changed files with 136 additions and 11 deletions

View File

@ -5,5 +5,5 @@ project(ceev)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS}) include_directories(${SDL2_INCLUDE_DIRS})
add_executable(ceev src/ceev.cc src/ceev.h) add_executable(ceev src/ceev.cc src/ceev.h src/colors.cc src/colors.h)
target_link_libraries(ceev ${SDL2_LIBRARIES}) target_link_libraries(ceev ${SDL2_LIBRARIES})

View File

@ -8,31 +8,36 @@ int usage() {
std::cout << "Run `" << program_invocation_short_name << " --help' for more information.\n" << std::endl; std::cout << "Run `" << program_invocation_short_name << " --help' for more information.\n" << std::endl;
return 1; return 1;
} }
int show_help() { int show_help() {
// TODO: Maybe put the colorings into functions? std::cout << program_invocation_short_name << " [" << cyan("command") << "] <" << bright_green("options") << ">\n";
std::cout << program_invocation_short_name << " [\x1b[36mcommand\x1b[0m] <\x1b[92moptions\x1b[0m>\n";
std::cout << "\n"; std::cout << "\n";
std::cout << "Usage:"; std::cout << "Usage:";
// ceev init // ceev init
std::cout << "\n*\t"; std::cout << "\n*\t";
std::cout << program_invocation_short_name << " \x1b[36minit \x1b[0m<\x1b[92m--force\x1b[0m>\n"; std::cout << program_invocation_short_name << cyan(" init ") << "<" << bright_green("--force") << ">\n";
std::cout << "\t\t"; std::cout << "\t\t";
std::cout << "Creates the CeeV file system. Can only be used "; std::cout << "Creates the CeeV file system. Can only be used ";
std::cout << "if the current folder is empty,"; std::cout << "if the current folder is empty,";
std::cout << "\n\t\tor when run with `\x1b[92m--force\x1b[0m'"; std::cout << "\n\t\tor when run with `" << bright_green("--force") << "'";
// ceev build // ceev build
std::cout << "\n*\t"; std::cout << "\n*\t";
std::cout << program_invocation_short_name << " \x1b[36mbuild\x1b[0m\n"; std::cout << program_invocation_short_name << cyan(" build") << "\n";
std::cout << "\t\t"; std::cout << "\t\t";
std::cout << "Not yet implemented"; std::cout << "Not yet implemented";
// ceev run // ceev run
std::cout << "\n*\t"; std::cout << "\n*\t";
std::cout << program_invocation_short_name << " \x1b[36mrun\x1b[0m\n"; std::cout << program_invocation_short_name << cyan(" run") << "\n";
std::cout << "\t\t";
std::cout << "Not yet implemented";
// ceev clean
std::cout << "\n*\t";
std::cout << program_invocation_short_name << cyan(" clean") << "\n";
std::cout << "\t\t"; std::cout << "\t\t";
std::cout << "Not yet implemented"; std::cout << "Not yet implemented";
// ceev --help // ceev --help
std::cout << "\n*\t"; std::cout << "\n*\t";
std::cout << program_invocation_short_name << " \x1b[36m--help\x1b[0m\n"; std::cout << program_invocation_short_name << cyan(" --help") << "\n";
std::cout << "\t\t"; std::cout << "\t\t";
std::cout << "This help page.\n"; std::cout << "This help page.\n";
std::cout << std::endl; std::cout << std::endl;
@ -40,13 +45,33 @@ int show_help() {
} }
int create_fs(std::deque<std::string> args) { int create_fs(std::deque<std::string> args) {
std::string cwd = fs::current_path(); fs::path cwd = fs::current_path();
if (!fs::is_empty(cwd) && args[0] != "--force") { if (!fs::is_empty(cwd) && args[0] != "--force") {
std::cerr << "ERROR: Folder not empty.\n" << std::cerr << "ERROR: Folder not empty.\n" <<
"Run the command with `--force' to run anyways" << std::endl; "Run the command with `--force' to run anyways" << std::endl;
return 1; return 1;
} }
std::cout << "running create_fs()" << std::endl; std::cout << "running create_fs()" << std::endl;
fs::create_directory(cwd.string() + "/.ceev", cwd);
fs::create_directory(cwd.string() + "/src", cwd);
std::ofstream config(cwd.string() + "/.ceev/config");
std::string directory = cwd.string().substr(cwd.parent_path().string().length() + 1);
std::cout << "Initializing project...\n";
std::cout << "You can change this information later by editing .ceev/config\n";
std::string project_name;
std::cout << "Project name [" << directory << "]: ";
std::getline(std::cin, project_name);
if (project_name == "") project_name = directory;
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';
std::string author;
std::cout << "Author: ";
std::getline(std::cin, author);
if (author == "") author = "Unknown";
return 0; return 0;
} }
int build_project(std::deque<std::string> args) { int build_project(std::deque<std::string> args) {
@ -57,7 +82,10 @@ int run_project(std::deque<std::string> args) {
std::cout << "Running project..." << std::endl; std::cout << "Running project..." << std::endl;
return 0; return 0;
} }
int clean_project(std::deque<std::string> args) {
std::cout << "Cleaning project..." << std::endl;
return 0;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc <= 1) { if (argc <= 1) {
return usage(); return usage();
@ -72,10 +100,12 @@ int main(int argc, char **argv) {
} }
if (a1 == "build") return build_project(args); if (a1 == "build") return build_project(args);
if (a1 == "run") return run_project(args); if (a1 == "run") return run_project(args);
if (a1 == "clean") return clean_project(args);
std::string kw; std::string kw;
if (a1.substr(0, 2) == "--") { if (a1.substr(0, 2) == "--") {
kw = a1.substr(2); kw = a1.substr(2);
if (kw == "help") return show_help(); if (kw == "help") return show_help();
} }
return 0; std::cerr << "ERROR: Unknown command `" << a1 << "'\n" << std::endl;
return usage();
} }

View File

@ -3,9 +3,12 @@
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <filesystem> #include <filesystem>
#include <fstream>
#include <iostream> #include <iostream>
#include <deque> #include <deque>
#include "colors.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
int usage(); int usage();
@ -13,4 +16,5 @@ int show_help();
int create_fs(std::deque<std::string> args); int create_fs(std::deque<std::string> args);
int build_project(std::deque<std::string> args); int build_project(std::deque<std::string> args);
int run_project(std::deque<std::string> args); int run_project(std::deque<std::string> args);
int clean_project(std::deque<std::string> args);
int main(int argc, char **argv); int main(int argc, char **argv);

69
src/colors.cc 100644
View File

@ -0,0 +1,69 @@
#include "colors.h"
void colors_test() {
std::cout << "Hello World";
}
std::string black(std::string input) {
return "\x1b[30m" + input + "\x1b[0m";
}
std::string red(std::string input) {
return "\x1b[31m" + input + "\x1b[0m";
}
std::string green(std::string input) {
return "\x1b[32m" + input + "\x1b[0m";
}
std::string yellow(std::string input) {
return "\x1b[33m" + input + "\x1b[0m";
}
std::string blue(std::string input) {
return "\x1b[34m" + input + "\x1b[0m";
}
std::string magenta(std::string input) {
return "\x1b[35m" + input + "\x1b[0m";
}
std::string cyan(std::string input) {
return "\x1b[36m" + input + "\x1b[0m";
}
std::string white(std::string input) {
return "\x1b[37m" + input + "\x1b[0m";
}
std::string bright_black(std::string input) {
return "\x1b[90m" + input + "\x1b[0m";
}
std::string bright_red(std::string input) {
return "\x1b[91m" + input + "\x1b[0m";
}
std::string bright_green(std::string input) {
return "\x1b[92m" + input + "\x1b[0m";
}
std::string bright_yellow(std::string input) {
return "\x1b[93m" + input + "\x1b[0m";
}
std::string bright_blue(std::string input) {
return "\x1b[94m" + input + "\x1b[0m";
}
std::string bright_magenta(std::string input) {
return "\x1b[95m" + input + "\x1b[0m";
}
std::string bright_cyan(std::string input) {
return "\x1b[96m" + input + "\x1b[0m";
}
std::string bright_white(std::string input) {
return "\x1b[97m" + input + "\x1b[0m";
}

22
src/colors.h 100644
View File

@ -0,0 +1,22 @@
#pragma once
#include <iostream>
#include <string>
void colors_test();
std::string black(std::string input);
std::string red(std::string input);
std::string green(std::string input);
std::string yellow(std::string input);
std::string blue(std::string input);
std::string magenta(std::string input);
std::string cyan(std::string input);
std::string white(std::string input);
std::string bright_black(std::string input);
std::string bright_red(std::string input);
std::string bright_green(std::string input);
std::string bright_yellow(std::string input);
std::string bright_blue(std::string input);
std::string bright_magenta(std::string input);
std::string bright_cyan(std::string input);
std::string bright_white(std::string input);