summaryrefslogtreecommitdiffhomepage
path: root/wfpctl/src/extras/cli/subcommanddispatcher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wfpctl/src/extras/cli/subcommanddispatcher.cpp')
-rw-r--r--wfpctl/src/extras/cli/subcommanddispatcher.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/wfpctl/src/extras/cli/subcommanddispatcher.cpp b/wfpctl/src/extras/cli/subcommanddispatcher.cpp
new file mode 100644
index 0000000000..4bb7868cd7
--- /dev/null
+++ b/wfpctl/src/extras/cli/subcommanddispatcher.cpp
@@ -0,0 +1,27 @@
+#include "stdafx.h"
+#include "subcommanddispatcher.h"
+#include "libcommon/string.h"
+#include <sstream>
+#include <stdexcept>
+#include <utility>
+
+void SubcommandDispatcher::addSubcommand(const std::wstring &command, Handler handler)
+{
+ m_commands.insert(std::make_pair(command, handler));
+}
+
+void SubcommandDispatcher::dispatch(const std::wstring &command, const std::vector<std::wstring> &arguments)
+{
+ auto selectedCommand = m_commands.find(command);
+
+ if (m_commands.end() == selectedCommand)
+ {
+ std::wstringstream ss;
+
+ ss << L"Unsupported subcommand '" << command << "'. Cannot complete request.";
+
+ throw std::runtime_error(common::string::ToAnsi(ss.str()).c_str());
+ }
+
+ selectedCommand->second(common::string::SplitKeyValuePairs(arguments));
+}