diff --git a/src/command.cpp b/src/command.cpp index dd45437..3bce3d0 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -30,7 +30,7 @@ void Command::addDefaultCommand(void (*func)(int argc, char *argv[])) } // run a command -void Command::runCommand(char *name, int argc, char *argv[]) +void Command::runCommand(std::string name, int argc, char *argv[]) { // std::cout << "Running command: " << name << std::endl; if (this->isInCommands(name)) @@ -50,7 +50,7 @@ void Command::runCommand(char *name, int argc, char *argv[]) } // check if a command is in the command map -bool Command::isInCommands(char *name) +bool Command::isInCommands(std::string name) { for (auto const &command : commands) { diff --git a/src/command.h b/src/command.h index 80234be..a6bff41 100644 --- a/src/command.h +++ b/src/command.h @@ -25,9 +25,9 @@ public: // 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[]); + void runCommand(std::string name, int argc, char *argv[]); // check if a command is in the command map - bool isInCommands(char *name); + bool isInCommands(std::string name); std::string listCommands(); diff --git a/src/main.cpp b/src/main.cpp index 6b91095..548a5a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,9 @@ void input(int argc, char *argv[]) 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); } @@ -93,11 +95,25 @@ void editScript(std::string name) #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 << " [script] - Runs a script if autom has not command with that name" << 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; } \ No newline at end of file diff --git a/src/main.h b/src/main.h index 232abb5..9c6f034 100644 --- a/src/main.h +++ b/src/main.h @@ -31,6 +31,8 @@ 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[]);