# # # patch "cmd.hh" # from [c70a5318d2742490c10e5012573872540b7d987b] # to [562e34f7eab6eba5cdc5556886358371049a3204] # # patch "commands.cc" # from [7f856bb18471ee934cfb4dd80c5c8be0d9ca71d1] # to [20f15e3021688159839211bc361eb2694773f4c9] # # patch "monotone.cc" # from [3612544da8f7619e8dbff006f547075bc3c6ace5] # to [8c79550c27a5c737f2a5415a2586d7a696341d59] # ============================================================ --- cmd.hh c70a5318d2742490c10e5012573872540b7d987b +++ cmd.hh 562e34f7eab6eba5cdc5556886358371049a3204 @@ -43,7 +43,8 @@ namespace commands options::options_type m_opts; children_set m_children; - std::map< command_id, command * > find_completions(utf8 const & prefix); + std::map< command_id, command * > + find_completions(utf8 const & prefix, command_id const & completed); command * find_child_by_name(utf8 const & name) const; public: @@ -82,7 +83,9 @@ namespace commands bool has_name(utf8 const & name) const; command * find_command(command_id const & id); - std::set< command_id > complete_command(command_id const & id); + std::set< command_id > + complete_command(command_id const & id, + command_id completed = command_id()); }; }; ============================================================ --- commands.cc 7f856bb18471ee934cfb4dd80c5c8be0d9ca71d1 +++ commands.cc 20f15e3021688159839211bc361eb2694773f4c9 @@ -315,7 +315,7 @@ namespace commands { } map< command_id, command * > - command::find_completions(utf8 const & prefix) + command::find_completions(utf8 const & prefix, command_id const & completed) { map< command_id, command * > matches; @@ -331,13 +331,15 @@ namespace commands { for (names_set::const_iterator iter2 = child->names().begin(); iter2 != child->names().end(); iter2++) { + command_id caux = completed; + caux.push_back(*iter2); if (prefix == *iter2) - matches[child->ident(*iter2)] = child; + matches[caux] = child; else if (prefix().length() < (*iter2)().length()) { utf8 p(string((*iter2)(), 0, prefix().length())); if (prefix == p) - matches[child->ident(*iter2)] = child; + matches[caux] = child; } } } @@ -346,17 +348,21 @@ namespace commands { } set< command_id > - command::complete_command(command_id const & id) + command::complete_command(command_id const & id, + command_id completed) { I(this != CMD_REF(__root__) || !id.empty()); I(!id.empty()); + if (completed.empty() && this != CMD_REF(__root__)) + completed = ident(); + set< command_id > matches; utf8 component = *(id.begin()); command_id remaining(id.begin() + 1, id.end()); - map< command_id, command * > m2 = find_completions(component); + map< command_id, command * > m2 = find_completions(component, completed); for (map< command_id, command * >::const_iterator iter = m2.begin(); iter != m2.end(); iter++) { @@ -368,7 +374,9 @@ namespace commands { else { I(remaining.size() == id.size() - 1); - set< command_id > maux = child->complete_command(remaining); + command_id caux = completed; + caux.push_back(i2[i2.size() - 1]); + set< command_id > maux = child->complete_command(remaining, caux); if (maux.empty()) matches.insert(i2); else @@ -950,7 +958,7 @@ CMD_HIDDEN(test3, "", CMD_REF(__root__), CMD(test2, "alias2", CMD_REF(__root__), "", "", "", options::opts::none) {} CMD_HIDDEN(test3, "", CMD_REF(__root__), "", "", "", options::opts::none) {} -CMD_GROUP(testg, "", CMD_REF(__root__), "", "", options::opts::none); +CMD_GROUP(testg, "aliasg", CMD_REF(__root__), "", "", options::opts::none); CMD(testg1, "", CMD_REF(testg), "", "", "", options::opts::none) {} CMD(testg2, "", CMD_REF(testg), "", "", "", options::opts::none) {} CMD_HIDDEN(testg3, "", CMD_REF(testg), "", "", "", options::opts::none) {} @@ -1004,6 +1012,12 @@ UNIT_TEST(commands, complete_command) BOOST_CHECK(id == make_command_id("testg testg1")); } + // Multi-word identifier, non-primary names. + { + command_id id = complete_command(mkargs("al testg1")); + BOOST_CHECK(id == make_command_id("aliasg testg1")); + } + // Single-word identifier, one level deep. { command_id id = complete_command(mkargs("testg1")); @@ -1063,11 +1077,12 @@ UNIT_TEST(commands, command_complete_com { command_id id = make_command_id("alias"); set< command_id > matches = CMD_REF(__root__)->complete_command(id); - BOOST_REQUIRE(matches.size() == 2); + BOOST_REQUIRE(matches.size() == 3); set< command_id > expected; expected.insert(make_command_id("alias1")); expected.insert(make_command_id("alias2")); + expected.insert(make_command_id("aliasg")); BOOST_CHECK(matches == expected); } ============================================================ --- monotone.cc 3612544da8f7619e8dbff006f547075bc3c6ace5 +++ monotone.cc 8c79550c27a5c737f2a5415a2586d7a696341d59 @@ -155,12 +155,12 @@ commands::command_id read_options(option commands::command_id cmd2 = cmd; - if (opts.args[0]() != cmd[0]()) + if (cmd2[0]().find(opts.args[0]()) != 0) cmd2.erase(cmd2.begin()); for (args_vector::size_type i = 0; i < cmd2.size(); i++) { - I(cmd2[i]().find(opts.args[i]()) == 0); + I(cmd2[i]().find(opts.args[0]()) == 0); opts.args.erase(opts.args.begin()); } }