mirror of
https://github.com/Yet-Another-DreamTeam/quicknote.git
synced 2026-03-13 08:09:41 +00:00
add basic commands
This commit is contained in:
parent
988f9bdec3
commit
ac9831542f
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.html": "html",
|
||||
"*.jsste": "plaintext",
|
||||
"sstream": "cpp"
|
||||
}
|
||||
}
|
||||
@ -4,13 +4,61 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#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
45
src/commands.h
Normal 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
18
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;
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "./setup.h"
|
||||
#include "./command.h"
|
||||
#include "./commands.h"
|
||||
|
||||
Setup setup;
|
||||
// Command command;
|
||||
Command command;
|
||||
Loading…
x
Reference in New Issue
Block a user