# # # patch "commands.cc" # from [fc85ba13a4c414a07b9db41ca16bfa841f69f9b3] # to [3d9b83b76565a4adc444c901213d31a8f57dee09] # # patch "commands.hh" # from [1bb28efb43eab84cfda439f04ba931a138131f74] # to [42fb189d08be5911d7214224cfb3a839256b4d4f] # # patch "monotone.cc" # from [4d185e254cd053d66f61dc3871f8a0a49f80441a] # to [d694be98990cdee4061475fba5000692c5bc95a0] # # patch "simplestring_xform.cc" # from [b96fd4fb6ee790e87f4572f1605cf32541d2f4b8] # to [6f39553595fc5a19a7f0e68d695209f53c74ab70] # # patch "simplestring_xform.hh" # from [f0f9686a17a7c75e3c657c61e2550ed975e72e01] # to [b43d9ade47e5112c9d6cbf3a9a7ecf3f3daeb433] # ============================================================ --- commands.cc fc85ba13a4c414a07b9db41ca16bfa841f69f9b3 +++ commands.cc 3d9b83b76565a4adc444c901213d31a8f57dee09 @@ -413,29 +413,6 @@ namespace commands return path; } - // Generates a string of the form "a1, ..., aN" where a1 through aN are - // all the elements of the 'names' set. The input set cannot be empty. - static string format_names(command::names_set const & names) - { - I(names.size() > 0); - - string text; - -/* - set< string >::const_iterator iter = names.begin(); - do - { - text += *iter; - iter++; - if (iter != names.end()) - text += ", "; - } - while (iter != names.end()); -*/ - - return text; - } - // Prints the abstract description of the given command or command group // properly indented. The tag starts at column two. The description has // to start, at the very least, two spaces after the tag's end position; @@ -443,7 +420,6 @@ namespace commands static void describe(const string & tag, const string & abstract, size_t colabstract, ostream & out) { - /* // The algorithm below avoids printing an space on entry (note that // there are two before the tag but just one after it) and considers // that the colabstract is always one unit less than that given on @@ -458,13 +434,13 @@ namespace commands out << ' '; col = colabstract - 1; - vector< utf8 > words = split_into_words(abstract); + vector< utf8 > words = split_into_words(utf8(abstract)); const size_t maxcol = terminal_width(); vector< utf8 >::const_iterator i = words.begin(); while (i != words.end()) { - string const & word = *i; + string const & word = (*i)(); if (col + word.length() + 1 >= maxcol) { @@ -485,7 +461,7 @@ namespace commands { do i++; - while (i != words.end() && (*i) == ""); + while (i != words.end() && (*i)().empty()); if (i == words.end()) break; else @@ -505,13 +481,11 @@ namespace commands i++; } out << endl; - */ } - static void explain_children(set< command * > const & children, + static void explain_children(command::children_set const & children, ostream & out) { - /* I(children.size() > 0); vector< command * > sorted; @@ -520,7 +494,8 @@ namespace commands for (command::children_set::const_iterator i = children.begin(); i != children.end(); i++) { - size_t len = display_width(utf8(format_names((*i)->names()) + " ")); + size_t len = display_width(join_words((*i)->names())) + + display_width(utf8(" ")); if (colabstract < len) colabstract = len; @@ -531,8 +506,8 @@ namespace commands for (vector< command * >::const_iterator i = sorted.begin(); i != sorted.end(); i++) - describe(format_names((*i)->names()), (*i)->abstract(), colabstract, out); - */ + describe(join_words((*i)->names())(), (*i)->abstract(), colabstract, + out); } static void explain_cmd_usage(string const & name, ostream & out) @@ -586,13 +561,14 @@ namespace commands */ } - void explain_usage(string const & name, ostream & out) + void explain_usage(command_id const & ident, ostream & out) { - if (find_command(name) != NULL) - explain_cmd_usage(name, out); + vector< utf8 > rest; // XXX + if (CMD_REF(public)->find_child_by_components(ident, rest) != CMD_REF(public)) + explain_cmd_usage("", out); // XXX else { - I(name.empty()); + I(ident.empty()); // TODO Wrap long lines in these messages. out << "Top-level commands:" << endl << endl; @@ -990,28 +966,6 @@ UNIT_TEST(commands, complete_command) cc_aux(group, "test_sub", CMD_REF(test_subcmd), ""); cc_aux(group, "bar", group, "bar"); } - -UNIT_TEST(commands, format_names) -{ - using commands::format_names; - - set< string > s; - - s.clear(); - s.insert("a"); - BOOST_CHECK(format_names(s) == "a"); - - s.clear(); - s.insert("a"); - s.insert("b"); - BOOST_CHECK(format_names(s) == "a, b"); - - s.clear(); - s.insert("a"); - s.insert("b"); - s.insert("c"); - BOOST_CHECK(format_names(s) == "a, b, c"); -} #endif // BUILD_UNIT_TESTS // Local Variables: ============================================================ --- commands.hh 1bb28efb43eab84cfda439f04ba931a138131f74 +++ commands.hh 42fb189d08be5911d7214224cfb3a839256b4d4f @@ -23,7 +23,7 @@ namespace commands { namespace commands { typedef std::vector< utf8 > command_id; - void explain_usage(std::string const & cmd, std::ostream & out); + void explain_usage(command_id const & cmd, std::ostream & out); command_id complete_command(args_vector const & args, args_vector & rest); int process(app_state & app, std::string const & ident, ============================================================ --- monotone.cc 4d185e254cd053d66f61dc3871f8a0a49f80441a +++ monotone.cc d694be98990cdee4061475fba5000692c5bc95a0 @@ -293,9 +293,9 @@ cpp_main(int argc, char ** argv) usage_stream << F("Options specific to '%s %s':") % ui.prog_name % u.which << "\n\n"; usage_stream << cmd_options.instantiate(&app.opts).get_usage_str() << '\n'; } + */ commands::explain_usage(u.which, usage_stream); - */ if (app.opts.help) return 0; else ============================================================ --- simplestring_xform.cc b96fd4fb6ee790e87f4572f1605cf32541d2f4b8 +++ simplestring_xform.cc 6f39553595fc5a19a7f0e68d695209f53c74ab70 @@ -245,22 +245,44 @@ UNIT_TEST(simplestring_xform, join_words UNIT_TEST(simplestring_xform, join_words) { - vector< utf8 > s; + vector< utf8 > v; + set< utf8 > s; + v.clear(); + v.push_back(utf8("a")); + BOOST_CHECK(join_words(v)() == "a"); + BOOST_CHECK(join_words(v, ", ")() == "a"); + s.clear(); - s.push_back(utf8("a")); + s.insert(utf8("a")); BOOST_CHECK(join_words(s)() == "a"); + BOOST_CHECK(join_words(s, ", ")() == "a"); + v.clear(); + v.push_back(utf8("a")); + v.push_back(utf8("b")); + BOOST_CHECK(join_words(v)() == "a b"); + BOOST_CHECK(join_words(v, ", ")() == "a, b"); + s.clear(); - s.push_back(utf8("a")); - s.push_back(utf8("b")); + s.insert(utf8("b")); + s.insert(utf8("a")); BOOST_CHECK(join_words(s)() == "a b"); + BOOST_CHECK(join_words(s, ", ")() == "a, b"); + v.clear(); + v.push_back(utf8("a")); + v.push_back(utf8("b")); + v.push_back(utf8("c")); + BOOST_CHECK(join_words(v)() == "a b c"); + BOOST_CHECK(join_words(v, ", ")() == "a, b, c"); + s.clear(); - s.push_back(utf8("a")); - s.push_back(utf8("b")); - s.push_back(utf8("c")); + s.insert(utf8("b")); + s.insert(utf8("a")); + s.insert(utf8("c")); BOOST_CHECK(join_words(s)() == "a b c"); + BOOST_CHECK(join_words(s, ", ")() == "a, b, c"); } UNIT_TEST(simplestring_xform, split_into_words) ============================================================ --- simplestring_xform.hh f0f9686a17a7c75e3c657c61e2550ed975e72e01 +++ simplestring_xform.hh b43d9ade47e5112c9d6cbf3a9a7ecf3f3daeb433 @@ -25,17 +25,21 @@ std::vector< utf8 > split_into_words(utf std::vector< utf8 > split_into_words(utf8 const & in); -template< class T > -T join_words(std::vector< T > const & in) +template< template< typename > class T1, class T2 > +T2 join_words(T1< T2 > const & in, std::string const & sep = " ") { std::string str; - for (typename std::vector< T >::size_type i = 0; i < in.size(); i++) + typename T1< T2 >::const_iterator iter = in.begin(); + for (;;) { - str += in[i](); - if (i + 1 < in.size()) - str += ' '; + str += (*iter)(); + iter++; + if (iter == in.end()) + break; + else + str += sep; } - return T(str); + return T2(str); } void prefix_lines_with(std::string const & prefix,