arg_router  1.4.0
C++ command line argument parsing and routing
unknown_argument_handling.hpp
1 // Copyright (C) 2023 by Camden Mannett.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
4 
5 #pragma once
6 
7 #include "arg_router/utility/utf8/levenshtein_distance.hpp"
8 
9 namespace arg_router::parsing
10 {
19 template <typename Node>
20 [[noreturn]] void unknown_argument_exception(const Node& node, token_type unknown_token)
21 {
22  auto matching_node_and_parents =
23  utility::utf8::closest_matching_child_node(node, unknown_token);
24  if (matching_node_and_parents.empty()) {
26  } else {
27  auto tokens = vector<parsing::token_type>{unknown_token};
28  tokens.reserve(matching_node_and_parents.size() + 1);
29  tokens.insert(tokens.end(),
30  matching_node_and_parents.rbegin(),
31  matching_node_and_parents.rend());
32 
34  }
35 }
36 } // namespace arg_router::parsing
void unknown_argument_exception(const Node &node, token_type unknown_token)
vector< parsing::token_type > closest_matching_child_node(const Node &node, parsing::token_type token)
std::vector< T, config::allocator< T > > vector
Definition: basic_types.hpp:39