monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] [PATCH] new CMD_FOR_AUTOMATE macro


From: Thomas Keller
Subject: [Monotone-devel] [PATCH] new CMD_FOR_AUTOMATE macro
Date: Fri, 11 May 2007 17:59:48 +0200
User-agent: Thunderbird 2.0.0.0 (X11/20070326)

Hi all!

Attached is a patch which introduces a new CMD_FOR_AUTOMATE macro in cmd.hh, which basically makes certain commands available over automate (and therefor stdio) without writing duplicated code.

For now I found only one flaw: the help output of mtn automate rename. The original command has a two-line arguments description and apparently this gets a little shaked up somewhere.

This hasn't been heavily tested and basically only works for those commands which do not explicitely write to stdout (N macros etc. seem to get the proper output stream though), so I miss some magic to read out stdout and actually write it into output (if this is at all possible, i.e. stdout wasn't flushed yet).

Opinions are very welcome!

Thomas.

--
ICQ: 85945241 | SIP: 1-747-027-0392 | http://www.thomaskeller.biz
> Guitone, a frontend for monotone: http://guitone.thomaskeller.biz
> Music lyrics and more: http://musicmademe.com
#
# old_revision [e843889bffd2836632123dc439dd5880e3b6ac7b]
#
# patch "cmd.hh"
#  from [5c6809b9a65951b6e69d3bb80ff2d6d42781c511]
#    to [24ad4199c72cf7479819cc62823ae20b410fa7a1]
# 
# patch "cmd_ws_commit.cc"
#  from [26f58cb8a976a0db3ae0609f04bf3e962ab78e56]
#    to [ac75e337c0197aefb903eb0c140027e8d10467a7]
#
============================================================
--- cmd.hh      5c6809b9a65951b6e69d3bb80ff2d6d42781c511
+++ cmd.hh      24ad4199c72cf7479819cc62823ae20b410fa7a1
@@ -152,7 +152,7 @@ namespace commands {                    
     cmd_ ## C() : command(#C, realcommand##_cmd.cmdgroup,            \
                           realcommand##_cmd.params_,                 \
                           realcommand##_cmd.desc_, true,             \
-                          realcommand##_cmd.opts)                 \
+                          realcommand##_cmd.opts)                    \
     {}                                                               \
     virtual std::string desc();                                      \
     virtual void exec(app_state & app,                               \
@@ -207,9 +207,36 @@ void automation::auto_ ## NAME :: run(st
                                       app_state & app,              \
                                       std::ostream & output) const
 
+#define CMD_FOR_AUTOMATE(NAME, CMD_NAME)                            \
+namespace automation {                                              \
+  struct auto_ ## NAME : public automate                            \
+  {                                                                 \
+    auto_ ## NAME ()                                                \
+      : automate(#NAME, commands::CMD_NAME##_cmd.params_,           \
+                 options::options_type() |                          \
+                 commands::CMD_NAME##_cmd.opts)                     \
+    {}                                                              \
+    void run(std::vector<utf8> args, std::string const & help_name, \
+                     app_state & app, std::ostream & output) const; \
+    virtual ~auto_ ## NAME() {}                                     \
+  };                                                                \
+  static auto_ ## NAME NAME ## _auto;                               \
+}                                                                   \
+void automation::auto_ ## NAME :: run(std::vector<utf8> args,       \
+                                      std::string const & help_name,\
+                                      app_state & app,              \
+                                      std::ostream & output) const  \
+{                                                                   \
+    try                                                             \
+    {                                                               \
+      commands::process(app, std::string(#CMD_NAME), args);         \
+    }                                                               \
+    catch (usage &)                                                 \
+    {                                                               \
+      N(false, F("wrong argument count"));                          \
+    }                                                               \
+}
 
-
-
 // Local Variables:
 // mode: C++
 // fill-column: 76
============================================================
--- cmd_ws_commit.cc    26f58cb8a976a0db3ae0609f04bf3e962ab78e56
+++ cmd_ws_commit.cc    ac75e337c0197aefb903eb0c140027e8d10467a7
@@ -209,6 +209,8 @@ CMD(revert, N_("workspace"), N_("[PATH].
   app.work.maybe_update_inodeprints();
 }
 
+CMD_FOR_AUTOMATE(revert, revert)
+
 CMD(disapprove, N_("review"), N_("REVISION"),
     N_("disapprove of a particular revision"),
     options::opts::branch | options::opts::messages | options::opts::date |
@@ -339,6 +341,8 @@ CMD(add, N_("workspace"), N_("[PATH]..."
   app.work.perform_additions(paths, add_recursive, !app.opts.no_ignore);
 }
 
+CMD_FOR_AUTOMATE(add, add);
+
 CMD(drop, N_("workspace"), N_("[PATH]..."),
     N_("drop files from workspace"),
     options::opts::bookkeep_only | options::opts::missing | 
options::opts::recursive)
@@ -368,6 +372,7 @@ ALIAS(rm, drop);
 
 ALIAS(rm, drop);
 
+CMD_FOR_AUTOMATE(drop, drop);
 
 CMD(rename, N_("workspace"),
     N_("SRC DEST\n"
@@ -393,6 +398,7 @@ ALIAS(mv, rename);
 
 ALIAS(mv, rename);
 
+CMD_FOR_AUTOMATE(rename, rename);
 
 CMD(pivot_root, N_("workspace"), N_("NEW_ROOT PUT_OLD"),
     N_("rename the root directory\n"
@@ -413,6 +419,8 @@ CMD(pivot_root, N_("workspace"), N_("NEW
   app.work.perform_pivot_root(new_root, put_old, app.opts.bookkeep_only);
 }
 
+CMD_FOR_AUTOMATE(pivot_root, pivot_root);
+
 CMD(status, N_("informative"), N_("[PATH]..."), N_("show status of workspace"),
     options::opts::depth | options::opts::exclude)
 {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]