mirror of
https://github.com/Yet-Another-DreamTeam/quicknote.git
synced 2026-03-13 00:07:25 +00:00
add helpcommand if argc < 2
This commit is contained in:
parent
6589f344e4
commit
37786bc860
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,6 +28,7 @@
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
quicknote
|
||||
*.out
|
||||
*.app
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ class Command : public lpstd::Singleton<Command>
|
||||
|
||||
private:
|
||||
std::list<commandInfo> commands = {};
|
||||
std::string defaultCommandName = "help";
|
||||
|
||||
public:
|
||||
Command(/* args */)
|
||||
@ -44,27 +45,42 @@ public:
|
||||
std::string getHelpAsString()
|
||||
{
|
||||
std::string help = "";
|
||||
|
||||
std::list<commandInfo> sortedCommands = this->commands;
|
||||
|
||||
sortedCommands.sort([](const commandInfo &a, const commandInfo &b) {
|
||||
return a.name < b.name;
|
||||
});
|
||||
|
||||
for (auto &commandInfo : sortedCommands)
|
||||
for (auto &commandInfo : this->commands)
|
||||
{
|
||||
help += commandInfo.name + " - " + commandInfo.description + "\n";
|
||||
}
|
||||
return help;
|
||||
}
|
||||
|
||||
void callCommand(std::string command,int argc, char *argv[] )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void execute(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cout << "Command not found" << std::endl;
|
||||
throw lpstd::exceptions::ParameterException("argc < 2");
|
||||
std::cout << "Command not found \n" << std::endl;
|
||||
// throw lpstd::exceptions::ParameterException("argc < 2");
|
||||
|
||||
this->callCommand(defaultCommandName, argc, argv);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user