Elaztek Developer Hub
Blamite Game Engine - Tool (Library)
A command-line utility that aids in the creation of Blamite Cache (.map) Files.
HelpCommand.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Strings/components/logger/logger.h>
4 
5 #include "../ToolCommand.hpp"
6 #include "../console.h"
7 
8 #ifdef TOOL_LIB_EXPORTS
9 #define TOOL_LIB_API __declspec(dllexport)
10 #else
11 #define TOOL_LIB_API __declspec(dllimport)
12 #endif
13 
20 {
21 private:
22  std::string app_name_label = "tool";
23 
24 public:
26  {
27  command = "help";
28  syntax = "help [command]";
29  description = "shows a list of commands, or additional information for a specific command";
30  }
31 
39  void SetApplicationLabelName(std::string name)
40  {
41  app_name_label = name;
42  }
43 
44  int execute(std::vector<std::string> args)
45  {
46  std::vector<ToolCommand*> commands = BlamTool::Console::GetRegisteredCommands();
47 
48  if (args.size() == 0)
49  {
50  BlamStrings::Logger::LogEvent("usage: " + app_name_label + " verb <options..>");
51 
52  for (int i = 0; i < commands.size(); i++)
53  {
54  BlamStrings::Logger::LogEvent(" " + commands.at(i)->GetSyntax());
55  }
56 
57  BlamStrings::Logger::LogEvent("for additional information on a command, run '" + app_name_label + " help <command>'");
58  }
59  else
60  {
61  ToolCommand* matching_command = nullptr;
62 
63  for (int i = 0; i < commands.size(); i++)
64  {
65  if (commands.at(i)->GetCommandName() == args.at(0))
66  {
67  matching_command = commands.at(i);
68  break;
69  }
70  }
71 
72  if (matching_command)
73  {
74  BlamStrings::Logger::LogEvent("information for command: " + matching_command->GetCommandName());
75  BlamStrings::Logger::LogEvent(" description: " + matching_command->GetDescription());
76  BlamStrings::Logger::LogEvent(" usage: " + matching_command->GetSyntax());
77  }
78  else
79  {
80  BlamStrings::Logger::LogEvent("command not found: '" + args.at(0) + "', run '" + app_name_label + " help' for a list of commands");
81  }
82  }
83 
84  return 0;
85  }
86 };
ToolCommand::GetSyntax
std::string GetSyntax()
Retrieves the syntax of the command.
Definition: ToolCommand.hpp:39
HelpCommand::execute
int execute(std::vector< std::string > args)
Executes the command.
Definition: HelpCommand.hpp:44
ToolCommand::GetCommandName
std::string GetCommandName()
Retrieves the name of the command.
Definition: ToolCommand.hpp:29
HelpCommand
Class for the Help command.
Definition: HelpCommand.hpp:19
HelpCommand::HelpCommand
HelpCommand()
Definition: HelpCommand.hpp:25
HelpCommand::SetApplicationLabelName
void SetApplicationLabelName(std::string name)
Updates the application name label.
Definition: HelpCommand.hpp:39
BlamTool::Console::GetRegisteredCommands
TOOL_LIB_API std::vector< ToolCommand * > GetRegisteredCommands()
Retrieves the list of registered commands.
Definition: console.cpp:124
ToolCommand::GetDescription
std::string GetDescription()
Retrieves the description of the command.
Definition: ToolCommand.hpp:49
TOOL_LIB_API
#define TOOL_LIB_API
Definition: HelpCommand.hpp:11
ToolCommand
Base class representing a Tool command.
Definition: ToolCommand.hpp:15
commands
std::vector< ToolCommand * > commands
Definition: console.cpp:26