Elaztek Developer Hub
Blamite Game Engine - Strings  00313.05.23.21.2038.blamite
A library containing general purpose utilities and classes for use in multiple projects.
HelpCommand.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "../ToolCommand.hpp"
6 #include "../console.h"
7 
8 #ifdef STRINGS_EXPORTS
9 #define STRINGS_API __declspec(dllexport)
10 #else
11 #define STRINGS_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  BlamTool::Logger::LogEvent("usage: " + app_name_label + " verb <options..>");
40 
41  for (int i = 0; i < commands.size(); i++)
42  {
43  BlamTool::Logger::LogEvent(" " + commands.at(i)->GetSyntax());
44  }
45 
46  BlamTool::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  BlamTool::Logger::LogEvent("information for command: " + matching_command->GetCommandName());
64  BlamTool::Logger::LogEvent(" description: " + matching_command->GetDescription());
65  BlamTool::Logger::LogEvent(" usage: " + matching_command->GetSyntax());
66  }
67  else
68  {
69  BlamTool::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
STRINGS_API
#define STRINGS_API
Definition: HelpCommand.hpp:11
HelpCommand
Definition: HelpCommand.hpp:14
HelpCommand::HelpCommand
HelpCommand()
Definition: HelpCommand.hpp:21
HelpCommand::SetApplicationLabelName
void SetApplicationLabelName(std::string name)
Definition: HelpCommand.hpp:28
BlamTool::Logger::LogEvent
STRINGS_INTERNAL void LogEvent(BlamBasicLogMessage message)
Logs an event to Tool's log.
Definition: logger.cpp:10
logger.h
BlamTool::Console::GetRegisteredCommands
STRINGS_API std::vector< ToolCommand * > GetRegisteredCommands()
Definition: console.cpp:97
ToolCommand::GetDescription
std::string GetDescription()
Definition: ToolCommand.hpp:30
ToolCommand
Definition: ToolCommand.hpp:12
commands
std::vector< ToolCommand * > commands
Definition: console.cpp:11