# # # patch "commands.cc" # from [e01629d98b749ee08ea2a1791e1797e9967144a8] # to [2716a19c755c111ad09adc8bcaff6dac9fd3f30f] # # patch "commands.hh" # from [2f69ed33b4afae4b66a48e17dc18c8e4dc5e6014] # to [515cea06860a3b5577933cef00219e45a3bb8207] # # patch "monotone.cc" # from [e0a08b79c1ec487acaec9b77dd1b38df2d9bcc96] # to [3553c8e8f16acc2131fd92b227196f0b8b5afe6e] # ============================================================ --- commands.cc e01629d98b749ee08ea2a1791e1797e9967144a8 +++ commands.cc 2716a19c755c111ad09adc8bcaff6dac9fd3f30f @@ -590,21 +590,16 @@ namespace commands out); } - static void explain_cmd_usage(string const & name, ostream & out) + static void explain_cmd_usage(command * cmd, ostream & out) { - /* - command * cmd = find_command(name); // XXX Should be const. - assert(cmd != NULL); - vector< string > lines; - // XXX Use ui.prog_name instead of hardcoding 'mtn'. if (cmd->children().size() > 0) - out << F(safe_gettext("Subcommands for 'mtn %s':")) % - format_command_path(cmd) << "\n\n"; + out << F(safe_gettext("Subcommands of '%s %s':")) % + ui.prog_name % join_words(cmd->ident()) << "\n\n"; else - out << F(safe_gettext("Syntax specific to 'mtn %s':")) % - format_command_path(cmd) << "\n\n"; + out << F(safe_gettext("Syntax specific to '%s %s':")) % + ui.prog_name % join_words(cmd->ident()) << "\n\n"; // Print command parameters. string params = cmd->params(); @@ -613,16 +608,20 @@ namespace commands { for (vector::const_iterator j = lines.begin(); j != lines.end(); ++j) - out << " " << name << ' ' << *j << '\n'; + out << " " << join_words(cmd->ident())() << ' ' << *j << '\n'; out << '\n'; } - if (cmd->children().size() > 0) + // Explain children, if any. + if (!cmd->is_leaf()) { explain_children(cmd->children(), out); out << '\n'; } + // Print command description. + out << F(safe_gettext("Description for '%s %s':")) % + ui.prog_name % join_words(cmd->ident()) << "\n\n"; split_into_lines(cmd->desc(), lines); for (vector::const_iterator j = lines.begin(); j != lines.end(); ++j) @@ -631,20 +630,23 @@ namespace commands out << '\n'; } + // Print all available aliases. if (cmd->names().size() > 1) { command::names_set othernames = cmd->names(); - othernames.erase(name); - describe("", "Aliases: " + format_names(othernames) + ".", 4, out); + othernames.erase(cmd->primary_name()); + describe("", "Aliases: " + join_words(othernames, ", ")() + + ".", 4, out); out << '\n'; } - */ } void explain_usage(command_id const & ident, ostream & out) { - if (CMD_REF(__root__)->find_command(ident) != CMD_REF(__root__)) - explain_cmd_usage("", out); // XXX + command * cmd = find_command(ident); + + if (cmd != CMD_REF(__root__)) + explain_cmd_usage(cmd, out); else { I(ident.empty()); @@ -720,17 +722,10 @@ namespace commands return options::options_type(); } - options::options_type toplevel_command_options(string const & name) + options::options_type toplevel_command_options(command_id const & ident) { - command * cmd = NULL; // XXX find_command(name); - if (cmd != NULL) - { - return cmd->opts(); - } - else - { - return options::options_type(); - } + command * cmd = find_command(ident); + return cmd->opts(); } } //////////////////////////////////////////////////////////////////////// @@ -746,34 +741,9 @@ CMD(help, "", CMD_REF(informative), N_(" throw usage(command_id()); } -/* - vector< string > fooargs,rest; - for (vector< utf8 >::const_iterator i = args.begin(); i != args.end(); i++) - fooargs.push_back((*i)()); - command & cmd = commands::find_command(fooargs, rest); - - N(!rest.empty(), - F("could not match any command given '%s'; failed after '%s'") % - join_words(fooargs)() % join_words(rest)()); - + command_id id = commands::complete_command(args); app.opts.help = true; - throw usage(fooargs); -*/ - -/* - if (find_command(full_cmd) != NULL) - { - app.opts.help = true; - throw usage(full_cmd); - } - else - { - // No matched commands or command groups - N(!full_cmd.empty(), - F("unknown command '%s'") % idx(args, 0)()); - throw usage(""); - } -*/ + throw usage(id); } CMD_HIDDEN(crash, "", CMD_REF(__root__), "{ N | E | I | exception | signal }", ============================================================ --- commands.hh 2f69ed33b4afae4b66a48e17dc18c8e4dc5e6014 +++ commands.hh 515cea06860a3b5577933cef00219e45a3bb8207 @@ -30,7 +30,7 @@ namespace commands { int process(app_state & app, command_id const & ident, args_vector const & args); options::options_type command_options(args_vector const & cmdline); - options::options_type toplevel_command_options(std::string const & cmd); + options::options_type toplevel_command_options(command_id const & ident); }; struct usage ============================================================ --- monotone.cc e0a08b79c1ec487acaec9b77dd1b38df2d9bcc96 +++ monotone.cc 3553c8e8f16acc2131fd92b227196f0b8b5afe6e @@ -296,16 +296,14 @@ cpp_main(int argc, char ** argv) usage_stream << F("Usage: %s [OPTION...] command [ARG...]") % ui.prog_name << "\n\n"; usage_stream << options::opts::globals().instantiate(&app.opts).get_usage_str() << '\n'; -/* XXX // Make sure to hide documentation that's not part of // the current command. options::options_type cmd_options = commands::toplevel_command_options(u.which); if (!cmd_options.empty()) { - usage_stream << F("Options specific to '%s %s':") % ui.prog_name % u.which << "\n\n"; + usage_stream << F("Options specific to '%s %s':") % ui.prog_name % join_words(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)