aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Server/Console/ServerCliRegistry.h
blob: 5104b534549c4f472f59cc05b27bbe5e7813590e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

namespace ServerRuntime
{
	class IServerCliCommand;

	/**
	 * **CLI command registry**
	 */
	class ServerCliRegistry
	{
	public:
		/**
		 * **Register a command object**
		 *
		 * Validates name/aliases and adds lookup entries.
		 * コマンドの追加
		 */
		bool Register(std::unique_ptr<IServerCliCommand> command);

		/**
		 * **Find command by name or alias (const)**
		 *
		 * Returns null when no match exists.
		 */
		const IServerCliCommand *Find(const std::string &name) const;

		/**
		 * **Find mutable command by name or alias**
		 *
		 * Used by runtime dispatch path.
		 */
		IServerCliCommand *FindMutable(const std::string &name);

		/**
		 * **Suggest top-level command names**
		 *
		 * Adds matching command names and aliases to the output list.
		 */
		void SuggestCommandNames(const std::string &prefix, const std::string &linePrefix, std::vector<std::string> *out) const;

		/**
		 * **Get registered command list**
		 *
		 * Intended for help output and inspection.
		 */
		const std::vector<std::unique_ptr<IServerCliCommand>> &Commands() const;

	private:
		std::vector<std::unique_ptr<IServerCliCommand>> m_commands;
		std::unordered_map<std::string, IServerCliCommand *> m_lookup;
	};
}