mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
commit
002b12a048
10
README.md
10
README.md
@ -3,3 +3,13 @@
|
||||
__IN DEVELOPMENT, NOT READY FOR USE__
|
||||
|
||||
autom is a command line tool for executing shell scripts, independent of the working directory
|
||||
|
||||
|
||||
## Installation-Requirments:
|
||||
gcc
|
||||
make
|
||||
|
||||
## Compile:
|
||||
```bash
|
||||
make
|
||||
```
|
||||
@ -5,19 +5,22 @@ Command::Command() {}
|
||||
|
||||
Command::~Command() {}
|
||||
|
||||
// add a command to the command map
|
||||
void Command::addCommand(std::string name, void (*func)(int argc, char *argv[]))
|
||||
{
|
||||
commands[name] = func;
|
||||
}
|
||||
|
||||
// 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(char *name, int argc, char *argv[])
|
||||
{
|
||||
std::cout << "Running command: " << name << std::endl;
|
||||
// std::cout << "Running command: " << name << std::endl;
|
||||
if (this->isInCommands(name))
|
||||
{
|
||||
|
||||
@ -34,16 +37,17 @@ void Command::runCommand(char *name, int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// check if a command is in the command map
|
||||
bool Command::isInCommands(char *name)
|
||||
{
|
||||
for (auto const &command : commands)
|
||||
{
|
||||
if (command.first == name)
|
||||
{
|
||||
std::cout << "Command found: " << command.first << std::endl;
|
||||
// std::cout << "Command found: " << command.first << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
std::cout << "Command not found: " << name << std::endl;
|
||||
// std::cout << "Command not found: " << name << std::endl;
|
||||
return false;
|
||||
}
|
||||
@ -10,13 +10,20 @@ 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[]));
|
||||
// add a default command to the command map
|
||||
void addDefaultCommand(void (*func)(int argc,char *argv[]));
|
||||
// run a command
|
||||
void runCommand(char *name, int argc, char *argv[]);
|
||||
// check if a command is in the command map
|
||||
bool isInCommands(char *name);
|
||||
|
||||
private:
|
||||
// map of commands
|
||||
std::map<std::string, void (*)(int argc,char *argv[])> commands;
|
||||
// default command
|
||||
void (*defaultCommand)(int argc,char *argv[]);
|
||||
};
|
||||
|
||||
|
||||
@ -28,10 +28,14 @@ InputParser::InputParser(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
@ -13,7 +13,9 @@ class InputParser
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@ -13,6 +13,7 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
// input function for parsing arguments and creating commands and running them
|
||||
void input(int argc, char *argv[])
|
||||
{
|
||||
InputParser input(argc, argv);
|
||||
@ -21,23 +22,26 @@ void input(int argc, char *argv[])
|
||||
command.addCommand("run", runScript);
|
||||
command.addCommand("help", help);
|
||||
command.addDefaultCommand(runScript);
|
||||
command.runCommand(argv[1],argc, argv);
|
||||
command.runCommand(argv[1], argc, argv);
|
||||
}
|
||||
|
||||
void runScript(int argc,char *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::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;
|
||||
// std::cout << "Running script: " << script << std::endl;
|
||||
system(script.c_str());
|
||||
}
|
||||
|
||||
void help(int argc,char *argv[])
|
||||
// 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 << " [script] - Runs a script if autom has not command with that name" << std::endl;
|
||||
std::cout << " run [script] - Runs a script" << std::endl;
|
||||
std::cout << " help - Shows this help message" << std::endl;
|
||||
}
|
||||
15
src/main.h
15
src/main.h
@ -5,6 +5,7 @@
|
||||
#include "inputparser.h"
|
||||
#include "command.h"
|
||||
|
||||
// directory for autom scripts
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
std::string home = getenv("USERPROFILE");
|
||||
@ -12,13 +13,17 @@ std::string home = getenv("USERPROFILE");
|
||||
std::string home = getenv("HOME");
|
||||
#endif
|
||||
|
||||
// directory for autom scripts
|
||||
std::string dir = home + "/autom";
|
||||
|
||||
// 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[]);
|
||||
// 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[]);
|
||||
// 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[]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user