Merge pull request #1 from Yet-Another-DreamTeam/basic_setup

Basic setup
This commit is contained in:
Lucas Palomo Develop 2023-10-03 13:58:32 +02:00 committed by GitHub
commit 362bad642f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 201 additions and 1 deletions

3
.gitignore vendored
View File

@ -30,3 +30,6 @@
*.exe
*.out
*.app
# VSCode
.vscode

View File

@ -27,7 +27,7 @@ Use the following commands to create and manage notes:
- `./quicknote edit <ID> "New content"`: Updates the content of a specific note.
- `./quicknote delete <ID>`: Deletes a specific note based on its ID.
- `./quicknote remove <ID>`: Deletes a specific note based on its ID.
- `./quicknote search "Search term"`: Searches all notes for the specified search term and displays matches.

0
bin/.gitkeep Normal file
View File

11
makefile Normal file
View File

@ -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

64
src/command.h Normal file
View File

@ -0,0 +1,64 @@
#ifndef COMMAND_H
#define COMMAND_H
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <algorithm>
#include <iterator>
struct commandInfo
{
std::string name;
std::string description;
void (*func)(int argc, char *argv[]);
};
class Command
{
private:
std::list<commandInfo> 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<std::string> 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

45
src/commands.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef COMMANDS_H
#define COMMANDS_H
#include <iostream>
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

18
src/main.cpp Normal file
View File

@ -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;
}

7
src/main.h Normal file
View File

@ -0,0 +1,7 @@
#include <iostream>
#include "./setup.h"
#include "./command.h"
#include "./commands.h"
Setup setup;
Command command;

52
src/setup.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef SETUP_H
#define SETUP_H
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <filesystem>
#include <fstream>
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