Elaztek Developer Hub
Blamite Game Engine - Tool (Library)  00368.02.12.23.1347.blamite
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 
15 {
16 private:
17  std::string app_name_label = "tool";
18 
19 public:
20 
22  {
23  command = "help";
24  syntax = "help [command]";
25  description = "shows a list of commands, or additional information for a specific command";
26  }
27 
28  void SetApplicationLabelName(std::string name)
29  {
30  app_name_label = name;
31  }
32 
33  int execute(std::vector<std::string> args)
34  {
35  std::vector<ToolCommand*> commands = BlamTool::Console::GetRegisteredCommands();
36 
37  if (args.size() == 0)
38  {
39  BlamStrings::Logger::LogEvent("usage: " + app_name_label + " verb <options..>");
40 
41  for (int i = 0; i < commands.size(); i++)
42  {
43  BlamStrings::Logger::LogEvent(" " + commands.at(i)->GetSyntax());
44  }
45 
46  BlamStrings::Logger::LogEvent("for additional information on a command, run '" + app_name_label + " help <command>'");
47  }
48  else
49  {
50  ToolCommand* matching_command = nullptr;
51 
52  for (int i = 0; i < commands.size(); i++)
53  {
54  if (commands.at(i)->GetCommandName() == args.at(0))
55  {
56  matching_command = commands.at(i);
57  break;
58  }
59  }
60 
61  if (matching_command)
62  {
63  BlamStrings::Logger::LogEvent("information for command: " + matching_command->GetCommandName());
64  BlamStrings::Logger::LogEvent(" description: " + matching_command->GetDescription());
65  BlamStrings::Logger::LogEvent(" usage: " + matching_command->GetSyntax());
66  }
67  else
68  {
69  BlamStrings::Logger::LogEvent("command not found: '" + args.at(0) + "', run '" + app_name_label + " help' for a list of commands");
70  }
71  }
72 
73  return 0;
74  }
75 };
ToolCommand::GetSyntax
std::string GetSyntax()
Definition: ToolCommand.hpp:25
HelpCommand::execute
int execute(std::vector< std::string > args)
Definition: HelpCommand.hpp:33
ToolCommand::GetCommandName
std::string GetCommandName()
Definition: ToolCommand.hpp:20
HelpCommand
Definition: HelpCommand.hpp:14
HelpCommand::HelpCommand
HelpCommand()
Definition: HelpCommand.hpp:21
HelpCommand::SetApplicationLabelName
void SetApplicationLabelName(std::string name)
Definition: HelpCommand.hpp:28
BlamTool::Console::GetRegisteredCommands
TOOL_LIB_API std::vector< ToolCommand * > GetRegisteredCommands()
Definition: console.cpp:103
ToolCommand::GetDescription
std::string GetDescription()
Definition: ToolCommand.hpp:30
TOOL_LIB_API
#define TOOL_LIB_API
Definition: HelpCommand.hpp:11
ToolCommand
Definition: ToolCommand.hpp:12
commands
std::vector< ToolCommand * > commands
Definition: console.cpp:13