mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
no pointerfunctions in command
This commit is contained in:
parent
d91e80525d
commit
a634b13f72
@ -4,7 +4,6 @@ Command::Command() {}
|
||||
|
||||
Command::~Command() {}
|
||||
|
||||
|
||||
// add a command alias to the command map
|
||||
void Command::addCommandAlias(std::string name, std::string alias)
|
||||
{
|
||||
@ -15,8 +14,26 @@ void Command::addCommandAlias(std::string name, std::string alias)
|
||||
commands[alias] = mycommand;
|
||||
}
|
||||
|
||||
// add a command to the command map
|
||||
void Command::addCommand(std::string name, void (*func)(int argc, char *argv[]))
|
||||
// // add a command to the command map
|
||||
// void Command::addCommand(std::string name, void (*func)(int argc, char *argv[]))
|
||||
// {
|
||||
// CommandInfo mycommand{
|
||||
// name,
|
||||
// "",
|
||||
// func};
|
||||
// commands[name] = mycommand;
|
||||
// }
|
||||
|
||||
// void Command::addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]))
|
||||
// {
|
||||
// CommandInfo mycommand{
|
||||
// name,
|
||||
// description,
|
||||
// func};
|
||||
// commands[name] = mycommand;
|
||||
// }
|
||||
|
||||
void Command::addCommand(std::string name, std::function<void(int argc, char *argv[])> func)
|
||||
{
|
||||
CommandInfo mycommand{
|
||||
name,
|
||||
@ -25,7 +42,7 @@ void Command::addCommand(std::string name, void (*func)(int argc, char *argv[]))
|
||||
commands[name] = mycommand;
|
||||
}
|
||||
|
||||
void Command::addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]))
|
||||
void Command::addCommand(std::string name, std::string description, std::function<void(int argc, char *argv[])> func)
|
||||
{
|
||||
CommandInfo mycommand{
|
||||
name,
|
||||
@ -35,7 +52,12 @@ void Command::addCommand(std::string name, std::string description, void (*func)
|
||||
}
|
||||
|
||||
// add a default command to the command map
|
||||
void Command::addDefaultCommand(void (*func)(int argc, char *argv[]))
|
||||
// void Command::addDefaultCommand(void (*func)(int argc, char *argv[]))
|
||||
// {
|
||||
// defaultCommand = func;
|
||||
// }
|
||||
|
||||
void Command::addDefaultCommand(std::function<void(int argc, char *argv[])> func)
|
||||
{
|
||||
defaultCommand = func;
|
||||
}
|
||||
@ -61,7 +83,6 @@ void Command::runCommand(std::string name, int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check if a command is in the command map
|
||||
bool Command::isInCommands(std::string name)
|
||||
{
|
||||
@ -81,7 +102,6 @@ std::string Command::listCommands()
|
||||
{
|
||||
std::string list = "";
|
||||
|
||||
|
||||
for (std::map<std::string, CommandInfo>::iterator it = commands.begin(); it != commands.end(); ++it)
|
||||
{
|
||||
list += "\t" + it->second.name + " " + it->second.description + "\n";
|
||||
|
||||
@ -4,12 +4,14 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
|
||||
struct CommandInfo
|
||||
{
|
||||
std::string name;
|
||||
std::string description;
|
||||
void (*func)(int argc, char *argv[]);
|
||||
// void (*func)(int argc, char *argv[]);
|
||||
std::function<void(int argc, char *argv[])> func;
|
||||
};
|
||||
|
||||
class Command
|
||||
@ -21,10 +23,13 @@ public:
|
||||
// add a command alias to the command map
|
||||
void addCommandAlias(std::string name, std::string alias);
|
||||
// add a command to the command map
|
||||
void addCommand(std::string name, void (*func)(int argc, char *argv[]));
|
||||
void addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]));
|
||||
void addCommand(std::string name, std::function<void(int argc, char *argv[])> funcs);
|
||||
// void addCommand(std::string name, void (*func)(int argc, char *argv[]));
|
||||
void addCommand(std::string name, std::string description, std::function<void(int argc, char *argv[])> funcs);
|
||||
// void addCommand(std::string name, std::string description, void (*func)(int argc, char *argv[]));
|
||||
// add a default command to the command map
|
||||
void addDefaultCommand(void (*func)(int argc, char *argv[]));
|
||||
// void addDefaultCommand(void (*func)(int argc, char *argv[]));
|
||||
void addDefaultCommand(std::function<void(int argc, char *argv[])> funcs);
|
||||
// run a command
|
||||
void runCommand(std::string name, int argc, char *argv[]);
|
||||
// check if a command is in the command map
|
||||
@ -36,7 +41,8 @@ private:
|
||||
// map of commands
|
||||
std::map<std::string, CommandInfo> commands;
|
||||
// default command
|
||||
void (*defaultCommand)(int argc, char *argv[]);
|
||||
// void (*defaultCommand)(int argc, char *argv[]);
|
||||
std::function<void(int argc, char *argv[])> defaultCommand;
|
||||
};
|
||||
|
||||
#endif // COMMAND_H
|
||||
13
src/main.cpp
13
src/main.cpp
@ -20,17 +20,12 @@ void input(int argc, char *argv[])
|
||||
// std::cout << " [script] - Runs a script if autom has not command with that name" << std::endl;
|
||||
command.addCommand("run", "[script] - Runs a script", runScript);
|
||||
command.addCommand("help", "- Shows this help message", help);
|
||||
command.addCommandAlias("help", "h");
|
||||
|
||||
command.addCommand("ls", "- Lists all scripts ", listScripts);
|
||||
command.addCommandAlias("ls", "l");
|
||||
command.addCommand("add", "[script] - Adds a script", addScript);
|
||||
command.addCommandAlias("add", "a");
|
||||
command.addCommand("edit", "[script] - Edits a script", editScript);
|
||||
command.addCommandAlias("edit", "e");
|
||||
command.addCommand("remove", "[script] - Remove a script", removeScript);
|
||||
command.addCommandAlias("remove", "r");
|
||||
command.addCommand("show", "[script] - Shows a script", showScript);
|
||||
command.addCommandAlias("show", "s");
|
||||
command.addCommand("config", "<command> - Configures autom", config);
|
||||
|
||||
command.addDefaultCommand(runScript);
|
||||
@ -458,7 +453,7 @@ void addScript(int argc, char *argv[])
|
||||
|
||||
file.close();
|
||||
|
||||
editScript(argv[1], dir);
|
||||
editScript_fn(argv[1], dir);
|
||||
}
|
||||
|
||||
// edit a script in the autom directory
|
||||
@ -500,10 +495,10 @@ void editScript(int argc, char *argv[])
|
||||
dir = dir_options[num];
|
||||
}
|
||||
|
||||
editScript(argv[1], dir);
|
||||
editScript_fn(argv[1], dir);
|
||||
}
|
||||
|
||||
void editScript(std::string name, std::string dir)
|
||||
void editScript_fn(std::string name, std::string dir)
|
||||
{
|
||||
std::string script = dir + "/" + name;
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ void listScripts(int argc, char *argv[]);
|
||||
void addScript(int argc, char *argv[]);
|
||||
// edit a script in the autom directory
|
||||
void editScript(int argc, char *argv[]);
|
||||
void editScript(std::string name, std::string dir);
|
||||
void editScript_fn(std::string name, std::string dir);
|
||||
// remove a script in the autom directory
|
||||
void removeScript(int argc, char *argv[]);
|
||||
// show a script in the autom directory
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user