34 #include <ndn-cxx/util/logger.hpp>
40 static_assert(std::is_same_v<std::underlying_type_t<AvailableIn>,
41 std::underlying_type_t<ParseMode>>,
42 "AvailableIn and ParseMode must be declared with the same underlying type");
49 os << sep <<
"one-shot";
55 os << sep <<
"hidden";
69 return os <<
"one-shot";
73 return os << static_cast<int>(mode);
78 std::underlying_type_t<AvailableIn> modes)
83 new Command{def, execute,
static_cast<AvailableIn>(modes)});
86 m_commandOrder.push_back(m_commands.find({def.getNoun(), def.getVerb()}));
95 m_commands[{noun, verb2}] = m_commands.at({noun, verb});
99 std::vector<const CommandDefinition*>
102 std::vector<const CommandDefinition*> results;
103 for (
auto i : m_commandOrder) {
104 const auto& command = *i->second;
105 if ((command.modes &
static_cast<AvailableIn>(mode)) != 0 &&
106 (noun.empty() || noun == command.def.getNoun())) {
107 results.push_back(&command.def);
113 std::tuple<std::string, std::string, CommandArguments, ExecuteCommand>
118 const std::string& noun = tokens.size() > 0 ? tokens[0] :
"";
119 const std::string& verb = tokens.size() > 1 ? tokens[1] :
"";
121 NDN_LOG_TRACE(
"parse mode=" << mode <<
" noun=" << noun <<
" verb=" << verb);
123 auto i = m_commands.find({noun, verb});
124 if (i == m_commands.end() || (i->second->modes &
static_cast<AvailableIn>(mode)) == 0) {
129 NDN_LOG_TRACE(
"found command noun=" << def.
getNoun() <<
" verb=" << def.
getVerb());
131 size_t nConsumed = std::min<size_t>(2, tokens.size());
Print different string on first and subsequent usage.