# # # patch "cmd.hh" # from [9cdc32af87ddb16aa8be8db555a3e2be6b43a03d] # to [c70a5318d2742490c10e5012573872540b7d987b] # # patch "commands.cc" # from [b113c466e6fd2853f85e2b22ff60d983bf951e0b] # to [fb12f12d28bf8d15f9546de1736eb459709a61a5] # ============================================================ --- cmd.hh 9cdc32af87ddb16aa8be8db555a3e2be6b43a03d +++ cmd.hh c70a5318d2742490c10e5012573872540b7d987b @@ -43,7 +43,7 @@ namespace commands options::options_type m_opts; children_set m_children; - std::set< command * > find_completions(utf8 const & prefix); + std::map< command_id, command * > find_completions(utf8 const & prefix); command * find_child_by_name(utf8 const & name) const; public: @@ -59,7 +59,7 @@ namespace commands virtual ~command(void); - command_id ident(void) const; + command_id ident(utf8 const & name = utf8()) const; utf8 const & primary_name(void) const; names_set const & names(void) const; ============================================================ --- commands.cc b113c466e6fd2853f85e2b22ff60d983bf951e0b +++ commands.cc fb12f12d28bf8d15f9546de1736eb459709a61a5 @@ -187,15 +187,15 @@ namespace commands { } command_id - command::ident(void) const + command::ident(utf8 const & name) const { I(this != CMD_REF(__root__)); command_id i; if (parent() != CMD_REF(__root__)) - i = parent()->ident(); - i.push_back(primary_name()); + i = parent()->ident(utf8()); + i.push_back(name().empty() ? primary_name() : name); I(!i.empty()); return i; @@ -315,10 +315,10 @@ namespace commands { return cmd; } - std::set< command * > + map< command_id, command * > command::find_completions(utf8 const & prefix) { - std::set< command * > matches; + map< command_id, command * > matches; I(!prefix().empty()); @@ -333,12 +333,12 @@ namespace commands { iter2 != child->names().end(); iter2++) { if (prefix == *iter2) - matches.insert(child); + matches[child->ident(*iter2)] = child; else if (prefix().length() < (*iter2)().length()) { utf8 p(string((*iter2)(), 0, prefix().length())); if (prefix == p) - matches.insert(child); + matches[child->ident(*iter2)] = child; } } } @@ -350,31 +350,30 @@ namespace commands { command::complete_command(command_id const & id) { I(this != CMD_REF(__root__) || !id.empty()); + I(!id.empty()); set< command_id > matches; - if (id.empty()) - matches.insert(ident()); - else + utf8 component = *(id.begin()); + command_id remaining(id.begin() + 1, id.end()); + + map< command_id, command * > m2 = find_completions(component); + for (map< command_id, command * >::const_iterator iter = m2.begin(); + iter != m2.end(); iter++) { - utf8 component = *(id.begin()); - command_id remaining(id.begin() + 1, id.end()); + command_id const & i2 = (*iter).first; + command * child = (*iter).second; - set< command * > m2 = find_completions(component); - for (set< command * >::const_iterator iter = m2.begin(); - iter != m2.end(); iter++) + if (child->is_leaf() || remaining.empty()) + matches.insert(i2); + else { - if ((*iter)->is_leaf()) - matches.insert((*iter)->ident()); + I(remaining.size() == id.size() - 1); + set< command_id > maux = child->complete_command(remaining); + if (maux.empty()) + matches.insert(i2); else - { - I(remaining.size() == id.size() - 1); - set< command_id > maux = (*iter)->complete_command(remaining); - if (maux.empty()) - matches.insert((*iter)->ident()); - else - matches.insert(maux.begin(), maux.end()); - } + matches.insert(maux.begin(), maux.end()); } } @@ -987,7 +986,7 @@ UNIT_TEST(commands, complete_command) // Single-word identifier, non-primary name. { command_id id = complete_command(mkargs("alias1")); - BOOST_CHECK(id == make_command_id("test1")); + BOOST_CHECK(id == make_command_id("alias1")); } // Multi-word identifier. @@ -1035,7 +1034,7 @@ UNIT_TEST(commands, command_complete_com command_id id = make_command_id("alias1"); set< command_id > matches = CMD_REF(__root__)->complete_command(id); BOOST_REQUIRE(matches.size() == 1); - BOOST_CHECK(*matches.begin() == make_command_id("test1")); + BOOST_CHECK(*matches.begin() == make_command_id("alias1")); } // Single-word identifier with multiple matches. @@ -1058,8 +1057,8 @@ UNIT_TEST(commands, command_complete_com BOOST_REQUIRE(matches.size() == 2); set< command_id > expected; - expected.insert(make_command_id("test1")); - expected.insert(make_command_id("test2")); + expected.insert(make_command_id("alias1")); + expected.insert(make_command_id("alias2")); BOOST_CHECK(matches == expected); }