diff options
| author | Odd Stranne <odd@mullvad.net> | 2018-04-09 21:25:12 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2018-04-11 10:26:18 +0200 |
| commit | 0b5dd6c0dd8ad121c4a5c14c45c9b470dc1b9809 (patch) | |
| tree | ecf317c10a93c27365b4bb5e8a3c3241bab2e815 /wfpctl/src/extras/cli/subcommanddispatcher.cpp | |
| parent | a5f7cf5592003093caaa658516758fb3c45206d1 (diff) | |
| download | mullvadvpn-0b5dd6c0dd8ad121c4a5c14c45c9b470dc1b9809.tar.xz mullvadvpn-0b5dd6c0dd8ad121c4a5c14c45c9b470dc1b9809.zip | |
Add source files
Diffstat (limited to 'wfpctl/src/extras/cli/subcommanddispatcher.cpp')
| -rw-r--r-- | wfpctl/src/extras/cli/subcommanddispatcher.cpp | 27 |
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)); +} |
