From: g0dil Date: Wed, 3 Jun 2009 14:47:16 +0000 (+0000) Subject: Utils/Console: Add short help to 'ls' output X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=fd3a0e8ac95d1158e9ea661ddf9187b67c70169f;p=senf.git Utils/Console: Add short help to 'ls' output git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1220 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Console/Executor.cc b/Utils/Console/Executor.cc index 3bfa19b..e3f0921 100644 --- a/Utils/Console/Executor.cc +++ b/Utils/Console/Executor.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include "../../Utils/senfassert.hh" #include "../../Utils/Range.hh" #include "../../Utils/String.hh" @@ -222,14 +223,16 @@ prefix_ void senf::console::Executor::ls(std::ostream & output, DirectoryNode & node (*dir.back().lock()); DirectoryNode::child_iterator i (node.children().begin()); DirectoryNode::child_iterator const i_end (node.children().end()); - for (; i != i_end; ++i) { - output << i->first; - if (i->second->isDirectory()) - output << "/"; - else if (i->second->isLink()) - output << "@"; - output << "\n"; - } + boost::format fmt ("%s%s %|20t|%.59s\n"); + for (; i != i_end; ++i) + output << fmt + % i->first + % ( i->second->isDirectory() + ? "/" + : i->second->isLink() + ? "@" + : "" ) + % i->second->shorthelp(); } prefix_ void senf::console::Executor::pushd(ParseCommandInfo::TokensRange dir) diff --git a/Utils/Console/Executor.test.cc b/Utils/Console/Executor.test.cc index 833aa45..f02943b 100644 --- a/Utils/Console/Executor.test.cc +++ b/Utils/Console/Executor.test.cc @@ -99,7 +99,10 @@ BOOST_AUTO_UNIT_TEST(executor) parser.parse("ls", &setCommand); executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLS ); - BOOST_CHECK_EQUAL( os.str(), "dir1/\ndir2/\nsys/\n" ); + BOOST_CHECK_EQUAL( os.str(), + "dir1/ \n" + "dir2/ Helptext\n" + "sys/ \n" ); } { @@ -107,7 +110,7 @@ BOOST_AUTO_UNIT_TEST(executor) parser.parse("ls dir1", &setCommand); executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLS ); - BOOST_CHECK_EQUAL( os.str(), "dir3/\n" ); + BOOST_CHECK_EQUAL( os.str(), "dir3/ \n" ); } { @@ -213,7 +216,7 @@ BOOST_AUTO_UNIT_TEST(executorPolicy) parser.parse("ls dir1", &setCommand); executor(os, commands.back()); BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLS ); - BOOST_CHECK_EQUAL( os.str(), "dir3/\n" ); + BOOST_CHECK_EQUAL( os.str(), "dir3/ \n" ); } { diff --git a/Utils/Console/OverloadedCommand.cc b/Utils/Console/OverloadedCommand.cc index 8a0c631..cb405a7 100644 --- a/Utils/Console/OverloadedCommand.cc +++ b/Utils/Console/OverloadedCommand.cc @@ -160,7 +160,16 @@ prefix_ std::string senf::console::OverloadedCommandNode::v_shorthelp() { if (!shortdoc_.empty()) return shortdoc_; - return doc_.substr(0,doc_.find('\n')); + if (!doc_.empty()) + return doc_.substr(0,doc_.find('\n')); + Overloads::const_iterator i (overloads_.begin()); + Overloads::const_iterator const i_end (overloads_.end()); + for (; i != i_end; ++i) { + std::string overloadDoc ((*i)->doc()); + if (! overloadDoc.empty()) + return overloadDoc.substr(0,doc_.find('\n')); + } + return ""; } prefix_ void senf::console::OverloadedCommandNode::v_execute(boost::any & rv, diff --git a/Utils/Console/ParsedCommand.test.cc b/Utils/Console/ParsedCommand.test.cc index 74f57d7..5953658 100644 --- a/Utils/Console/ParsedCommand.test.cc +++ b/Utils/Console/ParsedCommand.test.cc @@ -303,7 +303,7 @@ BOOST_AUTO_UNIT_TEST(directoryReturn) SENF_CHECK_NO_THROW( parser.parse("test/test { ls; }", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); - BOOST_CHECK_EQUAL( ss.str(), "\ncb1\n" ); + BOOST_CHECK_EQUAL( ss.str(), "\ncb1 \n" ); } }