28 #include <ndn-cxx/util/logger.hpp> 36 static_assert(std::is_same<std::underlying_type<AvailableIn>::type,
37 std::underlying_type<ParseMode>::type>::value,
38 "AvailableIn and ParseMode must be declared with same underlying type");
45 os << sep <<
"one-shot";
51 os << sep <<
"hidden";
65 return os <<
"one-shot";
69 return os << static_cast<int>(mode);
74 std::underlying_type<AvailableIn>::type modes)
78 new Command{def, execute,
static_cast<AvailableIn>(modes)});
81 m_commandOrder.push_back(m_commands.find({def.getNoun(), def.getVerb()}));
90 m_commands[{noun, verb2}] = m_commands.at({noun, verb});
94 std::vector<const CommandDefinition*>
97 std::vector<const CommandDefinition*> results;
98 for (CommandContainer::const_iterator i : m_commandOrder) {
99 const Command& command = *i->second;
100 if ((command.modes & static_cast<AvailableIn>(mode)) != 0 &&
101 (noun.empty() || noun == command.def.getNoun())) {
102 results.push_back(&command.def);
108 std::tuple<std::string, std::string, CommandArguments, ExecuteCommand>
113 const std::string& noun = tokens.size() > 0 ? tokens[0] :
"";
114 const std::string& verb = tokens.size() > 1 ? tokens[1] :
"";
115 size_t nameLen = std::min<size_t>(2, tokens.size());
117 auto i = m_commands.find({noun, verb});
118 if (i == m_commands.end()) {
120 i = m_commands.find({noun,
"list"});
124 i = m_commands.find({noun,
""});
126 nameLen = std::min<size_t>(1, tokens.size());
128 if (i == m_commands.end() || (i->second->modes &
static_cast<AvailableIn>(mode)) == 0) {
129 BOOST_THROW_EXCEPTION(
Error(
"no such command: " + noun +
" " + verb));
133 NDN_LOG_TRACE(
"found command " << def.
getNoun() <<
" " << def.
getVerb());
135 return std::make_tuple(def.
getNoun(), def.
getVerb(), def.
parse(tokens, nameLen), i->second->execute);
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
print different string on first and subsequent usage