#
# patch "ChangeLog"
# from [d6117311bb0a53d044ff16bc5dd2694080dc41d3]
# to [46407fbc31edb53f7289bb08b03fd061bb957fe1]
#
# patch "commands.cc"
# from [48d30d4a94c85c3495de55cc06f7bdbb6347337b]
# to [79e9b2d502786c98561fb1389b67d056155990bf]
#
# patch "commands.hh"
# from [337024921561035de1d43473ecfcdc4e0016c618]
# to [80712c78001aaf6b8b1d9e6824c30da61ff4b690]
#
# patch "monotone.cc"
# from [0719867d9645dcd2322cce26a223889d9ae4fc78]
# to [c2bcf0d584759a7a8a3992fd539917afed84e95d]
#
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,14 @@
+2005-05-01 Richard Levitte
+
+ * commands.hh: Expose complete_commands().
+ * commands.cc (explain_usage, command_options, process): Don't
+ call complete_command(). Except the caller to have done that
+ already.
+ * monotone.cc (cpp_main): Start with completing the command after
+ processing the options. Use the result everywhere the command is
+ required. This avoids giving the user duplicate (or in some case,
+ triplicate) messages about command expansion.
+
2005-04-30 Richard Levitte
* contrib/monotone-nav.el (mnav-rev-make): Move it so it's defined
--- commands.cc
+++ commands.cc
@@ -159,11 +159,9 @@
{
map::const_iterator i;
- string completed = complete_command(cmd);
-
// try to get help on a specific command
- i = cmds.find(completed);
+ i = cmds.find(cmd);
if (i != cmds.end())
{
@@ -224,12 +222,10 @@
int process(app_state & app, string const & cmd, vector const & args)
{
- string completed = complete_command(cmd);
-
- if (cmds.find(completed) != cmds.end())
+ if (cmds.find(cmd) != cmds.end())
{
- L(F("executing %s command\n") % completed);
- cmds[completed]->exec(app, args);
+ L(F("executing %s command\n") % cmd);
+ cmds[cmd]->exec(app, args);
return 0;
}
else
@@ -241,11 +237,9 @@
set command_options(string const & cmd)
{
- string completed = complete_command(cmd);
-
- if (cmds.find(completed) != cmds.end())
+ if (cmds.find(cmd) != cmds.end())
{
- return cmds[completed]->options.opts;
+ return cmds[cmd]->options.opts;
}
else
{
--- commands.hh
+++ commands.hh
@@ -24,6 +24,7 @@
namespace commands {
void explain_usage(std::string const & cmd, std::ostream & out);
+ std::string complete_command(std::string const & cmd);
int process(app_state & app, std::string const & cmd, std::vector const & args);
std::set command_options(std::string const & cmd);
};
--- monotone.cc
+++ monotone.cc
@@ -370,17 +370,19 @@
F("syntax error near the \"%s\" option: %s") %
poptBadOption(ctx(), POPT_BADOPTION_NOALIAS) % poptStrerror(opt));
+ // complete the command if necessary
+
+ string cmd;
+ if (poptPeekArg(ctx()))
+ {
+ cmd = commands::complete_command(poptGetArg(ctx()));
+ }
+
// stop here if they asked for help
if (requested_help)
{
- if (poptPeekArg(ctx()))
- {
- string cmd(poptGetArg(ctx()));
- throw usage(cmd);
- }
- else
- throw usage("");
+ throw usage(cmd); // cmd may be empty, and that's fine.
}
// at this point we allow a working copy (meaning search for it
@@ -392,14 +394,12 @@
// main options processed, now invoke the
// sub-command w/ remaining args
- if (!poptPeekArg(ctx()))
+ if (cmd.empty())
{
throw usage("");
}
else
{
- string cmd(poptGetArg(ctx()));
-
// Make sure the local options used are really used by the
// given command.
set command_options = commands::command_options(cmd);