From d54ff2d7c4c63405cd3b059acac7490f4f96f2b5 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Tue, 3 Oct 2023 12:39:33 +0200 Subject: [PATCH 1/5] simple setup --- bin/.gitkeep | 0 makefile | 5 +++++ src/main.cpp | 7 +++++++ 3 files changed, 12 insertions(+) create mode 100644 bin/.gitkeep create mode 100644 makefile create mode 100644 src/main.cpp 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..ff1618c --- /dev/null +++ b/makefile @@ -0,0 +1,5 @@ +CC = g++ +CFLAGS = -Wall -O2 + +all: + $(CC) $(CFLAGS) -o ./bin/quicknote ./src/main.cpp \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..3d4f688 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char *argv[]) +{ + std::cout << "quicknote!" << std::endl; + return 0; +} \ No newline at end of file From 1ad84f155986a53c479480faa6833e3de2f0bcb9 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Tue, 3 Oct 2023 12:59:09 +0200 Subject: [PATCH 2/5] add basic setup.h --- makefile | 10 ++++++++-- src/main.cpp | 4 +++- src/main.h | 4 ++++ src/setup.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/main.h create mode 100644 src/setup.h diff --git a/makefile b/makefile index ff1618c..7f73578 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,11 @@ CC = g++ -CFLAGS = -Wall -O2 +CFLAGS = -std=c++17 -Wall -O2 -static -static-libgcc -static-libstdc++ all: - $(CC) $(CFLAGS) -o ./bin/quicknote ./src/main.cpp \ No newline at end of file + $(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/main.cpp b/src/main.cpp index 3d4f688..00ef488 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ -#include +#include "./main.h" int main(int argc, char *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..9da570c --- /dev/null +++ b/src/main.h @@ -0,0 +1,4 @@ +#include +#include "./setup.h" + +Setup setup; \ 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 From 988f9bdec35b74148447ffd9edad2dc7caf8f7e9 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Tue, 3 Oct 2023 13:04:29 +0200 Subject: [PATCH 3/5] preparing command structure and command.h --- README.md | 2 +- src/command.h | 16 ++++++++++++++++ src/main.cpp | 7 +++++++ src/main.h | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/command.h 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/src/command.h b/src/command.h new file mode 100644 index 0000000..dd03db5 --- /dev/null +++ b/src/command.h @@ -0,0 +1,16 @@ +#ifndef COMMAND_H +#define COMMAND_H + +#include +#include +#include +#include +#include +#include +#include + +class Command +{ +}; + +#endif // COMMAND_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 00ef488..db4e290 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,13 @@ 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); setup.runSetup(); std::cout << "quicknote!" << std::endl; diff --git a/src/main.h b/src/main.h index 9da570c..8a31bf8 100644 --- a/src/main.h +++ b/src/main.h @@ -1,4 +1,5 @@ #include #include "./setup.h" -Setup setup; \ No newline at end of file +Setup setup; +// Command command; \ No newline at end of file From ac9831542f0e2d35636ee0000dee0b95a3e06386 Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Tue, 3 Oct 2023 13:56:00 +0200 Subject: [PATCH 4/5] add basic commands --- .vscode/settings.json | 7 ++++++ src/command.h | 50 ++++++++++++++++++++++++++++++++++++++++++- src/commands.h | 45 ++++++++++++++++++++++++++++++++++++++ src/main.cpp | 18 +++++++++------- src/main.h | 4 +++- 5 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/commands.h 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 From 333c0d4da445db63fe562355a195b42abb15ce4d Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Tue, 3 Oct 2023 13:57:41 +0200 Subject: [PATCH 5/5] delete .vscode --- .gitignore | 3 +++ .vscode/settings.json | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 .vscode/settings.json 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/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7db5385..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "files.associations": { - "*.html": "html", - "*.jsste": "plaintext", - "sstream": "cpp" - } -} \ No newline at end of file