Utils/Console: Implement senf::console::dump() helper
g0dil [Fri, 5 Jun 2009 11:35:32 +0000 (11:35 +0000)]
Utils/Console: Repeat repeated command on console

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1224 270642c3-0616-0410-b53a-bc976706d245

Utils/Console/Node.cc
Utils/Console/Node.hh
Utils/Console/Node.test.cc
Utils/Console/Server.cc

index 5a04317..69e1bfb 100644 (file)
@@ -39,6 +39,31 @@ prefix_ senf::console::DirectoryNode & senf::console::root()
     return *rootNode;
 }
 
+namespace {
+    void dodump(std::ostream & output, unsigned level, senf::console::DirectoryNode & node)
+    {
+        std::string pad (2*level, ' ');
+        senf::console::DirectoryNode::child_iterator i (node.children().begin());
+        senf::console::DirectoryNode::child_iterator const i_end (node.children().end());
+        for (; i != i_end; ++i) {
+            output << pad << i->first;
+            if (i->second->isDirectory()) {
+                output << "/\n";
+                dodump(output, level+1,static_cast<senf::console::DirectoryNode&>(*i->second));
+            }
+            else if (i->second->isLink()) 
+                output << "@ -> " << i->second->followLink().path() << '\n';
+            else
+                output << '\n';
+        }
+    }
+}
+
+prefix_ void senf::console::dump(std::ostream & os, DirectoryNode & dir)
+{
+    dodump(os,0,dir);
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::console::GenericNode
 
index 4772b45..4cd15d1 100644 (file)
@@ -224,6 +224,7 @@ namespace console {
     class CommandNode;
 
     DirectoryNode & root();
+    void dump(std::ostream & os, DirectoryNode & dir=root());
 
     /** \brief Config/console node tree base-class
 
index aeea861..f88b91d 100644 (file)
@@ -117,6 +117,17 @@ BOOST_AUTO_UNIT_TEST(directoryNode)
     p->shortdoc("short doc");
     BOOST_CHECK_EQUAL( p->shorthelp(), "short doc" );
 
+    ss.str("");
+    senf::console::root()["dir2"].mkdir("dir4");
+    senf::console::root()["dir2"].link("link", *p);
+    senf::console::root()["dir2"]["dir4"].link("link", senf::console::root());
+    senf::console::dump(ss, senf::console::root()["dir2"]);
+    BOOST_CHECK_EQUAL( ss.str(),
+                       "dir3/\n"
+                       "dir4/\n"
+                       "  link@ -> /\n"
+                       "link@ -> /dir1\n" );
+
     BOOST_CHECK( senf::console::root().remove("dir1") == p );
     senf::console::root().remove("dir2");
     senf::console::root().remove("fn");
index afcf922..26a625f 100644 (file)
@@ -284,9 +284,10 @@ prefix_ void senf::console::Client::setNoninteractive()
 prefix_ std::string::size_type senf::console::Client::handleInput(std::string data,
                                                                   bool incremental)
 {
-    if (data.empty() && ! incremental)
+    if (data.empty() && ! incremental) {
         data = lastCommand_;
-    else
+        stream() << "repeat: " << data << std::endl;
+    } else
         lastCommand_ = data;
 
     std::string::size_type n (data.size());