add cmake workflow

This commit is contained in:
lucaspalomodevelop 2023-05-16 20:11:19 +02:00
parent a355286f5c
commit c8eed814d9
8 changed files with 372 additions and 365 deletions

View File

@ -1,29 +0,0 @@
name: C/C++ CI
on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
jobs:
build:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
# - name: configure
# run: ./configure
- name: make
run: make
# - name: make check
# run: make check
# - name: make distcheck
# run: make distcheck

36
.github/workflows/cmake.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: CMake
on:
push:
branches: [ "main", "dev" ]
pull_request:
branches: [ "main", "dev" ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

View File

@ -1,75 +1,75 @@
#include "command.h"
Command::Command() {}
Command::~Command() {}
// add a command to the command map
void Command::addCommand(std::string name, void (*func)(int argc, char *argv[]))
{
CommandInfo mycommand{
name,
"",
func};
commands[name] = mycommand;
}
void Command::addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]))
{
CommandInfo mycommand{
name,
description,
func};
commands[name] = mycommand;
}
// add a default command to the command map
void Command::addDefaultCommand(void (*func)(int argc, char *argv[]))
{
defaultCommand = func;
}
// run a command
void Command::runCommand(std::string name, int argc, char *argv[])
{
// std::cout << "Running command: " << name << std::endl;
if (this->isInCommands(name))
{
for (int i = 0; i < argc; i++)
{
argv[i] = argv[i + 1];
}
commands[name].func(argc, argv);
}
else
{
defaultCommand(argc, argv);
}
}
// check if a command is in the command map
bool Command::isInCommands(std::string name)
{
for (auto const &command : commands)
{
if (command.first == name)
{
// std::cout << "Command found: " << command.first << std::endl;
return true;
}
}
// std::cout << "Command not found: " << name << std::endl;
return false;
}
std::string Command::listCommands()
{
std::string list = "";
for (auto const &command : commands)
{
list += "\t" + command.second.name + " " + command.second.description + "\n";
}
return list;
#include "command.h"
Command::Command() {}
Command::~Command() {}
// add a command to the command map
void Command::addCommand(std::string name, void (*func)(int argc, char *argv[]))
{
CommandInfo mycommand{
name,
"",
func};
commands[name] = mycommand;
}
void Command::addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]))
{
CommandInfo mycommand{
name,
description,
func};
commands[name] = mycommand;
}
// add a default command to the command map
void Command::addDefaultCommand(void (*func)(int argc, char *argv[]))
{
defaultCommand = func;
}
// run a command
void Command::runCommand(std::string name, int argc, char *argv[])
{
// std::cout << "Running command: " << name << std::endl;
if (this->isInCommands(name))
{
for (int i = 0; i < argc; i++)
{
argv[i] = argv[i + 1];
}
commands[name].func(argc, argv);
}
else
{
defaultCommand(argc, argv);
}
}
// check if a command is in the command map
bool Command::isInCommands(std::string name)
{
for (auto const &command : commands)
{
if (command.first == name)
{
// std::cout << "Command found: " << command.first << std::endl;
return true;
}
}
// std::cout << "Command not found: " << name << std::endl;
return false;
}
std::string Command::listCommands()
{
std::string list = "";
for (auto const &command : commands)
{
list += "\t" + command.second.name + " " + command.second.description + "\n";
}
return list;
}

View File

@ -1,41 +1,41 @@
#ifndef COMMAND_H
#define COMMAND_H
#include <map>
#include <string>
#include <iostream>
struct CommandInfo
{
std::string name;
std::string description;
void (*func)(int argc, char *argv[]);
};
class Command
{
public:
Command(void);
~Command(void);
// add a command to the command map
void addCommand(std::string name, void (*func)(int argc, char *argv[]));
void addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]));
// add a default command to the command map
void addDefaultCommand(void (*func)(int argc, char *argv[]));
// run a command
void runCommand(std::string name, int argc, char *argv[]);
// check if a command is in the command map
bool isInCommands(std::string name);
std::string listCommands();
private:
// map of commands
std::map<std::string, CommandInfo> commands;
// default command
void (*defaultCommand)(int argc, char *argv[]);
};
#ifndef COMMAND_H
#define COMMAND_H
#include <map>
#include <string>
#include <iostream>
struct CommandInfo
{
std::string name;
std::string description;
void (*func)(int argc, char *argv[]);
};
class Command
{
public:
Command(void);
~Command(void);
// add a command to the command map
void addCommand(std::string name, void (*func)(int argc, char *argv[]));
void addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]));
// add a default command to the command map
void addDefaultCommand(void (*func)(int argc, char *argv[]));
// run a command
void runCommand(std::string name, int argc, char *argv[]);
// check if a command is in the command map
bool isInCommands(std::string name);
std::string listCommands();
private:
// map of commands
std::map<std::string, CommandInfo> commands;
// default command
void (*defaultCommand)(int argc, char *argv[]);
};
#endif // COMMAND_H

View File

@ -1,42 +1,42 @@
#include "./inputparser.h"
InputParser::InputParser(int argc, char *argv[])
{
for (int i = 1; i < argc; i++)
{
std::string arg(argv[i]);
if (arg.find("-") == 0)
{
std::string key = arg.substr(1);
if (i + 1 < argc)
{
std::string value(argv[i + 1]);
if (value.find("-") != 0)
{
args[key] = value;
i++;
}
else
{
args[key] = "";
}
}
else
{
args[key] = "";
}
}
}
}
// get the value of a key
std::string InputParser::getValue(std::string key)
{
return args[key];
}
// check if a key exists
bool InputParser::hasKey(std::string key)
{
return args.count(key) > 0;
#include "./inputparser.h"
InputParser::InputParser(int argc, char *argv[])
{
for (int i = 1; i < argc; i++)
{
std::string arg(argv[i]);
if (arg.find("-") == 0)
{
std::string key = arg.substr(1);
if (i + 1 < argc)
{
std::string value(argv[i + 1]);
if (value.find("-") != 0)
{
args[key] = value;
i++;
}
else
{
args[key] = "";
}
}
else
{
args[key] = "";
}
}
}
}
// get the value of a key
std::string InputParser::getValue(std::string key)
{
return args[key];
}
// check if a key exists
bool InputParser::hasKey(std::string key)
{
return args.count(key) > 0;
}

View File

@ -1,22 +1,22 @@
#ifndef INPUTPARSER_H
#define INPUTPARSER_H
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
class InputParser
{
std::map<std::string, std::string> args;
public:
InputParser(int argc, char *argv[]);
// get the value of a key
std::string getValue(std::string key);
// check if a key exists
bool hasKey(std::string key);
};
#ifndef INPUTPARSER_H
#define INPUTPARSER_H
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
class InputParser
{
std::map<std::string, std::string> args;
public:
InputParser(int argc, char *argv[]);
// get the value of a key
std::string getValue(std::string key);
// check if a key exists
bool hasKey(std::string key);
};
#endif // INPUTPARSER_H

View File

@ -1,119 +1,119 @@
#include "main.h"
int main(int argc, char *argv[])
{
#ifdef _WIN32
_mkdir(dir.c_str());
#else
mkdir(dir.c_str(), 0777);
#endif
input(argc, argv);
return 0;
}
// input function for parsing arguments and creating commands and running them
void input(int argc, char *argv[])
{
InputParser input(argc, argv);
// std::cout << " [script] - Runs a script if autom has not command with that name" << std::endl;
command.addCommand("run", "[script] - Runs a script", runScript);
command.addCommand("help", "- Shows this help message", help);
command.addCommand("ls", "- Lists all scripts ", listScripts);
command.addCommand("add", "[script] - Adds a script", addScript);
command.addCommand("new", "[script] - Adds a script", addScript);
command.addCommand("edit", "[script] - Edits a script", editScript);
command.addCommand("remove", "[script] - Remove a script", removeScript);
command.addDefaultCommand(runScript);
command.runCommand(argv[1], argc, argv);
}
// run a script with is in the autom directory
void runScript(int argc, char *argv[])
{
// std::cout << "Running script: " << argv[1] << std::endl;
std::string pre_script = "cd " + dir + " && ";
std::string script = pre_script + dir + "/" + argv[1];
// std::cout << "Running script: " << script << std::endl;
system(script.c_str());
}
// list all scripts in the autom directory
void listScripts(int argc, char *argv[])
{
std::cout << "Scripts:" << std::endl;
for (const auto &entry : std::filesystem::directory_iterator(dir))
{
std::string name = entry.path().filename().string();
std::cout << " " << name << std::endl;
}
}
// add a script in the autom directory
void addScript(int argc, char *argv[])
{
if (std::filesystem::exists(dir + "/" + argv[1]))
{
std::cout << "Script " << argv[1] << " already exists" << std::endl;
return;
}
std::cout << "Adding script: " << argv[1] << std::endl;
std::string script = dir + "/" + argv[1];
std::ofstream file(script);
#ifdef _WIN32
file << "@echo off" << std::endl;
_chmod(script.c_str(), _S_IREAD | _S_IWRITE);
#else
file << "#!/bin/bash" << std::endl;
system(("chmod +x " + script).c_str());
#endif
file.close();
editScript(argv[1]);
}
// edit a script in the autom directory
void editScript(int argc, char *argv[])
{
editScript(argv[1]);
}
void editScript(std::string name)
{
std::string script = dir + "/" + name;
#ifdef _WIN32
system(("notepad " + script).c_str());
#else
system(("nano " + script).c_str());
#endif
}
void removeScript(int argc, char *argv[])
{
std::string script = dir + "/" + argv[1];
if (std::filesystem::exists(script))
{
std::cout << "Removing script: " << argv[1] << std::endl;
std::filesystem::remove(script);
}
else
{
std::cout << "Script " << argv[1] << " does not exist" << std::endl;
}
}
// help function for showing help message
void help(int argc, char *argv[])
{
std::cout << "Usage: autom [command] [options]" << std::endl;
std::cout << "Commands:" << std::endl;
std::cout << "\t[script] - Runs a script if autom has not command with that name" << std::endl;
std::cout << command.listCommands() << std::endl;
#include "main.h"
int main(int argc, char *argv[])
{
#ifdef _WIN32
_mkdir(dir.c_str());
#else
mkdir(dir.c_str(), 0777);
#endif
input(argc, argv);
return 0;
}
// input function for parsing arguments and creating commands and running them
void input(int argc, char *argv[])
{
InputParser input(argc, argv);
// std::cout << " [script] - Runs a script if autom has not command with that name" << std::endl;
command.addCommand("run", "[script] - Runs a script", runScript);
command.addCommand("help", "- Shows this help message", help);
command.addCommand("ls", "- Lists all scripts ", listScripts);
command.addCommand("add", "[script] - Adds a script", addScript);
command.addCommand("new", "[script] - Adds a script", addScript);
command.addCommand("edit", "[script] - Edits a script", editScript);
command.addCommand("remove", "[script] - Remove a script", removeScript);
command.addDefaultCommand(runScript);
command.runCommand(argv[1], argc, argv);
}
// run a script with is in the autom directory
void runScript(int argc, char *argv[])
{
// std::cout << "Running script: " << argv[1] << std::endl;
std::string pre_script = "cd " + dir + " && ";
std::string script = pre_script + dir + "/" + argv[1];
// std::cout << "Running script: " << script << std::endl;
system(script.c_str());
}
// list all scripts in the autom directory
void listScripts(int argc, char *argv[])
{
std::cout << "Scripts:" << std::endl;
for (const auto &entry : std::filesystem::directory_iterator(dir))
{
std::string name = entry.path().filename().string();
std::cout << " " << name << std::endl;
}
}
// add a script in the autom directory
void addScript(int argc, char *argv[])
{
if (std::filesystem::exists(dir + "/" + argv[1]))
{
std::cout << "Script " << argv[1] << " already exists" << std::endl;
return;
}
std::cout << "Adding script: " << argv[1] << std::endl;
std::string script = dir + "/" + argv[1];
std::ofstream file(script);
#ifdef _WIN32
file << "@echo off" << std::endl;
_chmod(script.c_str(), _S_IREAD | _S_IWRITE);
#else
file << "#!/bin/bash" << std::endl;
system(("chmod +x " + script).c_str());
#endif
file.close();
editScript(argv[1]);
}
// edit a script in the autom directory
void editScript(int argc, char *argv[])
{
editScript(argv[1]);
}
void editScript(std::string name)
{
std::string script = dir + "/" + name;
#ifdef _WIN32
system(("notepad " + script).c_str());
#else
system(("nano " + script).c_str());
#endif
}
void removeScript(int argc, char *argv[])
{
std::string script = dir + "/" + argv[1];
if (std::filesystem::exists(script))
{
std::cout << "Removing script: " << argv[1] << std::endl;
std::filesystem::remove(script);
}
else
{
std::cout << "Script " << argv[1] << " does not exist" << std::endl;
}
}
// help function for showing help message
void help(int argc, char *argv[])
{
std::cout << "Usage: autom [command] [options]" << std::endl;
std::cout << "Commands:" << std::endl;
std::cout << "\t[script] - Runs a script if autom has not command with that name" << std::endl;
std::cout << command.listCommands() << std::endl;
}

View File

@ -1,42 +1,42 @@
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <filesystem>
#include <fstream>
#include "inputparser.h"
#include "command.h"
// directory for autom scripts
#ifdef _WIN32
#include <direct.h>
std::string home = getenv("USERPROFILE");
#else
std::string home = getenv("HOME");
#endif
// directory for autom scripts
std::string dir = home + "/autom";
Command command = Command();
// input function for parsing arguments and creating commands and running them
void input(int argc, char *argv[]);
// run a script with is in the autom directory
void runScript(int argc, char *argv[]);
// list all scripts in the autom directory
void listScripts(int argc, char *argv[]);
// add a script in the autom directory
void addScript(int argc, char *argv[]);
// edit a script in the autom directory
void editScript(int argc, char *argv[]);
void editScript(std::string name);
// remove a script in the autom directory
void removeScript(int argc, char *argv[]);
// help function for showing help message
void help(int argc, char *argv[]);
// void create(int argc,char *argv[]);
// void remove(int argc,char *argv[]);
// void list(int argc,char *argv[]);
// void edit(int argc,char *argv[]);
// void run(int argc,char *argv[]);
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <filesystem>
#include <fstream>
#include "inputparser.h"
#include "command.h"
// directory for autom scripts
#ifdef _WIN32
#include <direct.h>
std::string home = getenv("USERPROFILE");
#else
std::string home = getenv("HOME");
#endif
// directory for autom scripts
std::string dir = home + "/autom";
Command command = Command();
// input function for parsing arguments and creating commands and running them
void input(int argc, char *argv[]);
// run a script with is in the autom directory
void runScript(int argc, char *argv[]);
// list all scripts in the autom directory
void listScripts(int argc, char *argv[]);
// add a script in the autom directory
void addScript(int argc, char *argv[]);
// edit a script in the autom directory
void editScript(int argc, char *argv[]);
void editScript(std::string name);
// remove a script in the autom directory
void removeScript(int argc, char *argv[]);
// help function for showing help message
void help(int argc, char *argv[]);
// void create(int argc,char *argv[]);
// void remove(int argc,char *argv[]);
// void list(int argc,char *argv[]);
// void edit(int argc,char *argv[]);
// void run(int argc,char *argv[]);