diff --git a/src/command.cpp b/src/command.cpp index 9b69ad5..4388c1e 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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; } \ No newline at end of file diff --git a/src/command.h b/src/command.h index bc4eda4..adb202e 100644 --- a/src/command.h +++ b/src/command.h @@ -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 commands; + // default command void (*defaultCommand)(int argc,char *argv[]); }; diff --git a/src/inputparser.cpp b/src/inputparser.cpp index 3fb4681..63c18ac 100644 --- a/src/inputparser.cpp +++ b/src/inputparser.cpp @@ -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; diff --git a/src/inputparser.h b/src/inputparser.h index 46ee070..58061ae 100644 --- a/src/inputparser.h +++ b/src/inputparser.h @@ -11,9 +11,11 @@ class InputParser { std::map args; -public: +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); }; diff --git a/src/main.cpp b/src/main.cpp index 66fa4f8..91cbf17 100644 --- a/src/main.cpp +++ b/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; } \ No newline at end of file diff --git a/src/main.h b/src/main.h index 9634076..1e48027 100644 --- a/src/main.h +++ b/src/main.h @@ -5,6 +5,7 @@ #include "inputparser.h" #include "command.h" +// directory for autom scripts #ifdef _WIN32 #include 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[]);