diff --git a/.gitignore b/.gitignore index 259148f..83e4035 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ *.exe *.out *.app + +# VSCode +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 9ccb48c..9bea8b4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Use the following commands to create and manage notes: - `./quicknote edit "New content"`: Updates the content of a specific note. -- `./quicknote delete `: Deletes a specific note based on its ID. +- `./quicknote remove `: Deletes a specific note based on its ID. - `./quicknote search "Search term"`: Searches all notes for the specified search term and displays matches. diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/makefile b/makefile new file mode 100644 index 0000000..7f73578 --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +CC = g++ +CFLAGS = -std=c++17 -Wall -O2 -static -static-libgcc -static-libstdc++ + +all: + $(CC) $(CFLAGS) -o ./bin/quicknote ./src/main.cpp + +clean: + rm -rf ./bin/quicknote + +install: + cp ./bin/quicknote /usr/local/bin/quicknote diff --git a/src/command.h b/src/command.h new file mode 100644 index 0000000..56bd64a --- /dev/null +++ b/src/command.h @@ -0,0 +1,64 @@ +#ifndef COMMAND_H +#define COMMAND_H + +#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 new file mode 100644 index 0000000..322a8cb --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,18 @@ +#include "./main.h" + +int main(int argc, char *argv[]) +{ + 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; + return 0; +} \ No newline at end of file diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..77dfbeb --- /dev/null +++ b/src/main.h @@ -0,0 +1,7 @@ +#include +#include "./setup.h" +#include "./command.h" +#include "./commands.h" + +Setup setup; +Command command; \ No newline at end of file diff --git a/src/setup.h b/src/setup.h new file mode 100644 index 0000000..1f97bcc --- /dev/null +++ b/src/setup.h @@ -0,0 +1,52 @@ + + +#ifndef SETUP_H +#define SETUP_H + +#include +#include +#include +#include +#include + +class Setup +{ +private: +public: +#ifdef _WIN32 + + std::string home = getenv("USERPROFILE"); + std::string editor = "notepad.exe"; +#else + std::string home = getenv("HOME"); + std::string editor = "vim"; +#endif + Setup(/* args */) + { + home = home + "/.quicknote"; + + runSetup(); + } + + ~Setup() + { + } + + void createFolder() + { +#ifdef _WIN32 + mkdir((home).c_str()); +#else + mkdir((home).c_str(), 0777); +#endif + } + + void runSetup() + { + + if (!std::filesystem::exists(home)) + createFolder(); + } +}; + +#endif // SETUP_H \ No newline at end of file