Utils: Refactor hexdump() helper to move code out of template function
[senf.git] / Console / Executor.cc
index 4d9b2f9..3533a0e 100644 (file)
@@ -52,7 +52,7 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
     SENF_LOG(( "Executing: " << command ));
 
     if (cwd_.expired() || ! cwd().active())
-        cwd_ = root().thisptr();
+        cwd_ = root_;
 
     try {
         switch(command.builtin()) {
@@ -60,7 +60,7 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
             GenericNode & node ( traverseCommand(command.commandPath()) );
             DirectoryNode * dir ( dynamic_cast<DirectoryNode*>(&node) );
             if ( dir ) {
-                if (autocd_ && command.arguments().empty()) {
+                if (autocd_ && command.tokens().empty()) {
                     oldCwd_ = cwd_;
                     cwd_ = dir->thisptr();
                 } else
@@ -77,20 +77,20 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
                     && command.arguments().begin()->begin()->value() == "-") {
                     if (oldCwd_.expired() || ! oldCwd_.lock()->active()) {
                         oldCwd_ = cwd_;
-                        cwd_ = root().thisptr();
+                        cwd_ = root_;
                     } else
                         swap(cwd_, oldCwd_);
                 }
                 else {
                     oldCwd_ = cwd_;
-                    cwd_ = traverseDirectory(command.arguments().begin()[0]).thisptr();
+                    cwd_ = traverseDirectory(*command.arguments().begin()).thisptr();
                 }
             }
             break;
             
         case ParseCommandInfo::BuiltinLS : {
             DirectoryNode const & dir ( command.arguments()
-                                        ? traverseDirectory(command.arguments().begin()[0])
+                                        ? traverseDirectory(*command.arguments().begin())
                                         : cwd() );
             for (DirectoryNode::child_iterator i (dir.children().begin());
                  i != dir.children().end(); ++i) {
@@ -105,7 +105,7 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
         case ParseCommandInfo::BuiltinPUSHD :
             dirstack_.push_back(cwd_);
             if ( command.arguments() )
-                cwd_ = traverseDirectory(command.arguments().begin()[0]).thisptr();
+                cwd_ = traverseDirectory(*command.arguments().begin()).thisptr();
             break;
             
         case ParseCommandInfo::BuiltinPOPD :
@@ -120,7 +120,7 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
 
         case ParseCommandInfo::BuiltinHELP :
             GenericNode const & node (command.arguments() 
-                                      ? traverseNode(command.arguments().begin()[0])
+                                      ? traverseNode(*command.arguments().begin())
                                       : cwd());
             output << prettyName(typeid(node)) << " at " << node.path() << "\n\n";
             node.help(output);
@@ -138,17 +138,18 @@ prefix_ void senf::console::Executor::execute(std::ostream & output,
     catch (InvalidCommandException &) {
         output << "invalid command" << std::endl;
     }
+    catch (IgnoreCommandException &) {}
 }
 
 prefix_ senf::console::GenericNode &
-senf::console::Executor::traverseNode(ParseCommandInfo::argument_value_type const & path)
+senf::console::Executor::traverseNode(ParseCommandInfo::TokensRange const & path)
 {
     try {
-        return cwd().traverse(
+        return traverse(
+            cwd(),
             boost::make_iterator_range(
                 boost::make_transform_iterator(path.begin(), TraverseTokens()),
-                boost::make_transform_iterator(path.end(), TraverseTokens())),
-            autocomplete_);
+                boost::make_transform_iterator(path.end(), TraverseTokens())) );
     }
     catch (std::bad_cast &) {
         throw InvalidPathException();
@@ -162,7 +163,7 @@ prefix_ senf::console::GenericNode &
 senf::console::Executor::traverseCommand(ParseCommandInfo::CommandPathRange const & path)
 {
     try {
-        return cwd().traverse(path, autocomplete_);
+        return traverse(cwd(), path);
     }
     catch (std::bad_cast &) {
         throw InvalidPathException();
@@ -173,7 +174,7 @@ senf::console::Executor::traverseCommand(ParseCommandInfo::CommandPathRange cons
 }
 
 prefix_ senf::console::DirectoryNode &
-senf::console::Executor::traverseDirectory(ParseCommandInfo::argument_value_type const & path)
+senf::console::Executor::traverseDirectory(ParseCommandInfo::TokensRange const & path)
 {
     try {
         return dynamic_cast<DirectoryNode&>( traverseNode(path) );