From 71aa47185031e9efa696fbe943c2eaf2c52ef322 Mon Sep 17 00:00:00 2001 From: Kittycannon Date: Mon, 7 Sep 2026 21:43:32 -0600 Subject: [PATCH] added -here argument --- src/kmake/kmake.cpp | 114 +++++++++++++++++++++++++++++++++- src/kmake/kmake.hpp | 1 + src/kmake/project/Distro.cpp | 8 +++ src/kmake/project/Project.cpp | 23 +++++++ 4 files changed, 143 insertions(+), 3 deletions(-) diff --git a/src/kmake/kmake.cpp b/src/kmake/kmake.cpp index 9d330af..cc93576 100644 --- a/src/kmake/kmake.cpp +++ b/src/kmake/kmake.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include namespace kmake { @@ -20,6 +22,107 @@ namespace kmake { kmake_terminal << msg << style::RESET << '\n'; } + void createProject() { + namespace fs = std::filesystem; + + fs::path cwd = fs::current_path(); + string parent_dir = cwd.filename().string(); + + // Create folders + fs::create_directories("src"); + fs::create_directories("bin"); + fs::create_directories("out"); + + log("Created directories: src/, bin/, out/", Verbosity::NORMAL); + + // Create kmake.yml + string kmake_yml = R"(name: ')" + parent_dir + R"(' +author: '' # author and authors are added together +authors: [''] +descr: + - '' +# Amount of text to output +verbosity: normal +build: + # Set build folders + src: + path: './src' + targets: ['c','cpp'] # Set targets for compilation + out: + path: './out' + target: 'exe' + bin: + path: './bin' + target: 'o' + deps: + path: './bin' # Reuse binaries folder (default) + target: 'd' + rev_target: 'rd' # Extension for reverse dependencies + style: gcc # Dependency style of generated output + + # Set number of threads to use + # for compilation of multiple files + # 0 To turn off multithreading. + # Default: 0 + # Recommended: 4 + threads: 4 +vars: +distros: + default: + # Distro Vars (overrides global) + vars: + # Commands executed at the start + start: + - '' + # Commands to generate dependencies + deps: + - '' + # Commands to compile one file + # Files may be compiled on multiple threads + compile: + - '' + # Commands to link one file + link: + - '' + # Commands executed after linking program + end: + - '' +)"; + + std::ofstream yml_file("kmake.yml"); + if (yml_file.is_open()) { + yml_file << kmake_yml; + yml_file.close(); + log("Created kmake.yml", Verbosity::NORMAL); + } else { + log("Failed to create kmake.yml", Verbosity::LOW); + } + + // Create .code-workspace + string workspace = R"({ + "folders": [ + { + "path": "." + } + ], + "settings": { + "terminal.integrated.defaultProfile.windows": "Command Prompt", + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.defaultProfile.osx": "zsh" + } +})"; + + string workspace_name = parent_dir + ".code-workspace"; + std::ofstream ws_file(workspace_name); + if (ws_file.is_open()) { + ws_file << workspace; + ws_file.close(); + log("Created " + workspace_name, Verbosity::NORMAL); + } else { + log("Failed to create " + workspace_name, Verbosity::LOW); + } + } + void parseArgs(int argc, char* argv[]) { for (int i = 1; i < argc; ++i) { string arg = argv[i]; @@ -30,10 +133,12 @@ namespace kmake { args.list_distros = true; } else if (arg == "-descr" || arg == "--descr") { args.show_description = true; + } else if (arg == "-here" || arg == "--here") { + args.create_project = true; } else if (arg == "-verbosity" || arg == "--verbosity") { if (i + 1 >= argc) { log("Missing value for " + arg, Verbosity::LOW); - return; + continue; } string val = argv[++i]; if (val == "low") args.verbosity = Verbosity::LOW; @@ -42,11 +147,9 @@ namespace kmake { else if (val == "debug") args.verbosity = Verbosity::DEBUG; else { log("Invalid verbosity: " + val, Verbosity::LOW); - return; } } else if (arg[0] == '-') { log("Unknown option: " + arg, Verbosity::LOW); - return; } else { args.distros.push_back(arg); } @@ -57,6 +160,11 @@ namespace kmake { } int run() { + if (args.create_project) { + createProject(); + return 0; + } + if (args.show_version) { log("Kitty Make by Kittycannon @ 2026, all rights reserved", Verbosity::NORMAL); log("kmake version 1.0.0", Verbosity::NORMAL); diff --git a/src/kmake/kmake.hpp b/src/kmake/kmake.hpp index 76be7e2..0aeb87b 100644 --- a/src/kmake/kmake.hpp +++ b/src/kmake/kmake.hpp @@ -20,6 +20,7 @@ namespace kmake { bool show_version = false; bool list_distros = false; bool show_description = false; + bool create_project = false; string config_file = "kmake.yml"; } args; diff --git a/src/kmake/project/Distro.cpp b/src/kmake/project/Distro.cpp index c27899d..846d1ae 100644 --- a/src/kmake/project/Distro.cpp +++ b/src/kmake/project/Distro.cpp @@ -6,4 +6,12 @@ namespace kmake { Distro::~Distro() {} + optional Distro::getVar(const string& name) { + auto it = vars.find(name); + if (it != vars.end()) { + return it->second; + } + return {}; + } + } diff --git a/src/kmake/project/Project.cpp b/src/kmake/project/Project.cpp index b674776..9a78bc9 100644 --- a/src/kmake/project/Project.cpp +++ b/src/kmake/project/Project.cpp @@ -280,4 +280,27 @@ namespace kmake { return true; } + bool Project::hasDistro(const string& distro_name) { + return distros.find(distro_name) != distros.end(); + } + + Distro& Project::getDistro(const string& distro_name) { + auto it = distros.find(distro_name); + if (it != distros.end()) { + return it->second; + } + // Return reference to first distro if exists, otherwise create a default + // This should not happen if hasDistro is checked first + static Distro empty_distro; + return empty_distro; + } + + optional Project::getVar(const string& var_name) { + auto it = vars.find(var_name); + if (it != vars.end()) { + return it->second; + } + return {}; + } + }