Skip to content

Commit

Permalink
github actions fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lsproule committed Nov 5, 2023
1 parent 096534e commit 38ac141
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: CMake on a single platform

on:
push:
pull_request:
branches: [ "dev" ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ FetchContent_Declare(
GIT_REPOSITORY "https://github.com/curl/curl.git"
GIT_TAG "curl-8_3_0"
)

FetchContent_Declare(
termcolor
GIT_REPOSITORY "https://github.com/ikalnytskyi/termcolor.git"
GIT_TAG "v2.1.0"
)
)

FetchContent_MakeAvailable(nlohmann_json)
FetchContent_MakeAvailable(cxxopts)
FetchContent_MakeAvailable(curl)
FetchContent_MakeAvailable(termcolor)




file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR}
"src/**.cpp"
"src/**.c"
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace Command {
std::string project_name;
std::string project_type;
std::string project_description;
BuildServer build_server;
std::filesystem::path project_path;
std::string git{"null"};
std::string lang{"cpp"};
Expand Down Expand Up @@ -120,7 +121,8 @@ namespace Command {
bool help();
bool addFlag();
bool server();

bool setBuildServer(std::vector<BuildServer> servers);
bool getBuildServer();
bool addAuthors();
bool addDependency();
bool ftp();
Expand Down
125 changes: 111 additions & 14 deletions src/Command/CommandServer.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,60 @@
#include "Command.hpp"
#include "../Utils/General.hpp"
#include "../Utils/CLI.hpp"

namespace Command{
using namespace Utils::CLI;
bool getServerName(std::string& name){
std::cout << "Enter the name of the server: ";
std::getline(std::cin, name);
Prompt<std::string> *name_promp = new Prompt<std::string>("Enter the name of the server: ");
name_promp->Run();
name = name_promp->Get();
return true;
}
bool getServerAddress(std::string& address){
std::cout << "Enter the address of the server: ";
std::getline(std::cin, address);
Prompt<std::string> *address_promp = new Prompt<std::string>("Enter the address of the server: ");
address_promp->Run();
address = address_promp->Get();
return true;
}

bool getServerPort(std::string& port){
std::cout << "Enter the port of the server: ";
std::getline(std::cin, port);
Prompt<int> *port_promp = new Prompt<int>("Enter the port of the server: ");
port_promp->Run();
port = port_promp->Get();
return true;
}

bool getServerUsername(std::string& username){
std::cout << "Enter the username of the server: ";
std::getline(std::cin, username);
Prompt<std::string> *username_promp = new Prompt<std::string>("Enter the username of the server: ");
username_promp->Validator([](std::string username){
if (username == ""){
return false;
}
else if (username.length() > 256){
return false;
}
return true;
});
username_promp->Run();
username = username_promp->Get();
return true;
}
bool getServerAuthMethod(std::string& authMethod){
std::cout << "Enter the authentication method of the server[pem/password]: ";
std::getline(std::cin, authMethod);
Prompt<std::string> *authMethod_promp = new Prompt<std::string>("Enter the authentication method of the server[pem/password]: ");
authMethod_promp->Run();
authMethod = authMethod_promp->Get();
return true;
}
bool getServerPassword(std::string& password){
std::cout << "Enter the password of the server: ";
std::getline(std::cin, password);
Prompt<std::string> *password_promp = new Prompt<std::string>("Enter the password of the server: ");
password_promp->Run();
password = password_promp->Get();
return true;
}
bool getServerKey(std::string& key){
std::cout << "Enter path the ssh key for the server: ";
std::getline(std::cin, key);
Prompt<std::string> *key_promp = new Prompt<std::string>("Enter path the ssh key for the server: ");
key_promp->Run();
key = key_promp->Get();
return true;
}

Expand All @@ -49,6 +70,46 @@ Usage server:
)EOF" << std::endl;
return true;
}
bool serverList(std::vector<BuildServer> servers){
//TODO put this in the constructor
Utils::TableFormat table;
table.width = 20;
table << "Name" << "Address" << "Port" << "Username" << "AuthMethod" << ENDL;
for (auto& server: servers){
table << server.name << server.ip << server.port << server.username << server.authMethod << ENDL;
}

return true;
}

bool Interface::setBuildServer( std::vector<BuildServer> servers){
std::string name;
getServerName(name);
for (auto& server: servers){
std::cout << "server.name:" << server.name << std::endl;
std::cout << "name:" << name << std::endl;
if (server.name == name){

std::cout << "Found server" << std::endl;
std::ofstream file;
file.open(std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json");
json current_build_server = {
{"name", server.name},
{"address", server.ip},
{"port", server.port},
{"username", server.username},
{"authMethod", server.authMethod},
{"password", server.password.value_or("")},
{"key", server.key.value_or("")}
};
file << current_build_server;
return true;
}
}
std::cout << "Could not find server" << std::endl;
return false;
}

bool serverAdd(std::vector<BuildServer> servers){

std::string build_servers= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "build_server.json";
Expand Down Expand Up @@ -92,17 +153,31 @@ Usage server:
file << build_server_json;
return true;
}
bool Interface::getBuildServer(){
Utils::TableFormat table;
table.width = 20;
table << "Name" << "Address" << "Port" << "Username" << "AuthMethod" << ENDL;
table << ctx->build_server.name << ctx->build_server.ip << ctx->build_server.port << ctx->build_server.username << ctx->build_server.authMethod << ENDL;
return true;

}

bool Interface::server(){
std::fstream file;
std::string build_servers_dir= std::string(std::getenv("HOME")) + "/.config/cmaker/";
if (!std::filesystem::exists(build_servers_dir)){
std::filesystem::create_directory(build_servers_dir);
}
std::string build_servers= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "build_server.json";
std::string current_build_server= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json";
if (!std::filesystem::exists(build_servers)){
std::ofstream file(build_servers);
file << "[]";
}
if (!std::filesystem::exists(current_build_server)){
std::ofstream file(current_build_server);
file << "{}";
}
file.open(build_servers);

std::vector<BuildServer> servers;
Expand All @@ -114,6 +189,25 @@ Usage server:
std::cout << "Error: Could not load build_server.json" << std::endl;
return false;
}
try{
json current_build_server_json = json::parse(std::ifstream(current_build_server));
if (!current_build_server_json["name"].is_null()) {
ctx->build_server = BuildServer(
current_build_server_json["name"].get<std::string>(),
current_build_server_json["address"].get<std::string>(),
current_build_server_json["username"].get<std::string>(),
current_build_server_json["authMethod"].get<std::string>(),
current_build_server_json["password"].get<std::string>(),
current_build_server_json["key"].get<std::string>(),
current_build_server_json["port"].get<int>()
);
}

}
catch(json::exception &e){
std::cout << "Error: Could not load current_build_server.json" << std::endl;
return false;
}



Expand Down Expand Up @@ -142,10 +236,13 @@ Usage server:
else if (this->args->operator[]("subcommand").as<std::string>() == "remove") {
}
else if (this->args->operator[]("subcommand").as<std::string>() == "list") {
serverList(servers);
}
else if (this->args->operator[]("subcommand").as<std::string>() == "set") {
setBuildServer(servers);
}
else if (this->args->operator[]("subcommand").as<std::string>() == "get") {
getBuildServer();
}
else{
serverHelp();
Expand Down
13 changes: 13 additions & 0 deletions src/Command/CommandWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ namespace Command {
std::cout << "Error running project" << std::endl;
}

std::string current_build_server= std::string(std::getenv("HOME")) + "/.config/cmaker/" + "current_build_server.json";
json current_build_server_json = json::parse(std::ifstream(current_build_server));
if (!current_build_server_json["name"].is_null()) {
ctx->build_server = BuildServer(
current_build_server_json["name"].get<std::string>(),
current_build_server_json["address"].get<std::string>(),
current_build_server_json["username"].get<std::string>(),
current_build_server_json["authMethod"].get<std::string>(),
current_build_server_json["password"].get<std::string>(),
current_build_server_json["key"].get<std::string>(),
current_build_server_json["port"].get<int>()
);
}
// Call your recompilation command or any other action you want
},path);
return true;
Expand Down
1 change: 0 additions & 1 deletion src/Command/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ namespace Command {
this->LoadPackageJson();
}


using namespace cxxopts;
if (command == "init"){
OptionsInit::Init(this);
Expand Down
13 changes: 12 additions & 1 deletion src/Utils/General.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
#include <string>
#include <vector>
#include <nlohmann/json.hpp>

#include <iomanip>
#include <iostream>
namespace Utils {
using nlohmann::json;
std::string getFolderName();
std::vector<std::string> split(std::string str, char delimiter);
void toLower(std::string& str);
json fetchJson(std::string url);
std::string fetchText(std::string url);
struct TableFormat {
int width;
char fill;
TableFormat(): width(14), fill(' ') {}
template<typename T>
TableFormat& operator<<(const T& data) {
std::cout<< std::setw(width) << data << std::setfill(fill);
return *this;
}
};
}

0 comments on commit 38ac141

Please sign in to comment.