From: g0dil Date: Fri, 5 Jun 2009 11:35:32 +0000 (+0000) Subject: Utils/Console: Implement senf::console::dump() helper X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=2df3b9508714ca6ed45fed02cbd77de46a65be87;p=senf.git Utils/Console: Implement senf::console::dump() helper Utils/Console: Repeat repeated command on console git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1224 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Console/Node.cc b/Utils/Console/Node.cc index 5a04317..69e1bfb 100644 --- a/Utils/Console/Node.cc +++ b/Utils/Console/Node.cc @@ -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(*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 diff --git a/Utils/Console/Node.hh b/Utils/Console/Node.hh index 4772b45..4cd15d1 100644 --- a/Utils/Console/Node.hh +++ b/Utils/Console/Node.hh @@ -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 diff --git a/Utils/Console/Node.test.cc b/Utils/Console/Node.test.cc index aeea861..f88b91d 100644 --- a/Utils/Console/Node.test.cc +++ b/Utils/Console/Node.test.cc @@ -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"); diff --git a/Utils/Console/Server.cc b/Utils/Console/Server.cc index afcf922..26a625f 100644 --- a/Utils/Console/Server.cc +++ b/Utils/Console/Server.cc @@ -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());