added -here argument

This commit is contained in:
2026-09-07 21:43:32 -06:00
parent 4cb79a7e46
commit 71aa471850
4 changed files with 143 additions and 3 deletions
+111 -3
View File
@@ -3,6 +3,8 @@
#include <desktoplib/terminal/Terminal.hpp>
#include <cstdlib>
#include <sstream>
#include <filesystem>
#include <fstream>
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);
+1
View File
@@ -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;
+8
View File
@@ -6,4 +6,12 @@ namespace kmake {
Distro::~Distro() {}
optional<string> Distro::getVar(const string& name) {
auto it = vars.find(name);
if (it != vars.end()) {
return it->second;
}
return {};
}
}
+23
View File
@@ -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<string> Project::getVar(const string& var_name) {
auto it = vars.find(var_name);
if (it != vars.end()) {
return it->second;
}
return {};
}
}