diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7db5385 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "*.html": "html", + "*.jsste": "plaintext", + "sstream": "cpp" + } +} \ No newline at end of file diff --git a/src/command.h b/src/command.h index dd03db5..56bd64a 100644 --- a/src/command.h +++ b/src/command.h @@ -4,13 +4,61 @@ #include #include #include -#include +#include #include #include #include +struct commandInfo +{ + std::string name; + std::string description; + void (*func)(int argc, char *argv[]); +}; + class Command { + +private: + std::list commands = {}; + +public: + Command(/* args */) + { + } + + ~Command() + { + } + + void addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[])) + { + commandInfo command; + command.name = name; + command.description = description; + command.func = func; + this->commands.push_back(command); + } + + void execute(int argc, char *argv[]) + { + std::string command = argv[1]; + std::vector args; + for (int i = 2; i < argc; i++) + { + args.push_back(argv[i]); + } + + for (auto &commandInfo : this->commands) + { + if (commandInfo.name == command) + { + commandInfo.func(argc, argv); + return; + } + } + std::cout << "Command not found" << std::endl; + } }; #endif // COMMAND_H \ No newline at end of file diff --git a/src/commands.h b/src/commands.h new file mode 100644 index 0000000..b16ea9d --- /dev/null +++ b/src/commands.h @@ -0,0 +1,45 @@ +#ifndef COMMANDS_H +#define COMMANDS_H + +#include + +namespace commands +{ + void add(int argc, char *argv[]) + { + std::cout << "add" << std::endl; + } + + void list(int argc, char *argv[]) + { + std::cout << "list" << std::endl; + } + + void view(int argc, char *argv[]) + { + std::cout << "view" << std::endl; + } + + void edit(int argc, char *argv[]) + { + std::cout << "edit" << std::endl; + } + + void remove(int argc, char *argv[]) + { + std::cout << "remove" << std::endl; + } + + void search(int argc, char *argv[]) + { + std::cout << "search" << std::endl; + } + + void help(int argc, char *argv[]) + { + std::cout << "help" << std::endl; + } + +} // namespace commands + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index db4e290..322a8cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,15 +2,17 @@ int main(int argc, char *argv[]) { - // command.addCommand("add", "add a note", add); - // command.addCommand("list", "list all notes", list); - // command.addCommand("view", "remove a note", view); - // command.addCommand("edit", "edit a note", edit); - // command.addCommand("remove", "remove a note", remove); - // command.addCommand("search", "search quicknote", search); - // command.addCommand("help", "show help", help); + command.addCommand("add", "add a note", commands::add); + command.addCommand("list", "list all notes", commands::list); + command.addCommand("view", "remove a note", commands::view); + command.addCommand("edit", "edit a note", commands::edit); + command.addCommand("remove", "remove a note", commands::remove); + command.addCommand("search", "search quicknote", commands::search); + command.addCommand("help", "show help", commands::help); + + command.execute(argc, argv); setup.runSetup(); - std::cout << "quicknote!" << std::endl; + // std::cout << "quicknote!" << std::endl; return 0; } \ No newline at end of file diff --git a/src/main.h b/src/main.h index 8a31bf8..77dfbeb 100644 --- a/src/main.h +++ b/src/main.h @@ -1,5 +1,7 @@ #include #include "./setup.h" +#include "./command.h" +#include "./commands.h" Setup setup; -// Command command; \ No newline at end of file +Command command; \ No newline at end of file