{
SENF_LOG(( "Executing: " << command ));
- ///\fixme Whenever checking cwd_.expired(), we also need to check, wether
- /// the node is still connected to the root.
- if (cwd_.expired())
+ if (cwd_.expired() || ! cwd().active())
cwd_ = root().thisptr();
try {
switch(command.builtin()) {
case ParseCommandInfo::NoBuiltin :
+ traverseToCommand(command.commandPath())(output, command.arguments());
break;
-
+
case ParseCommandInfo::BuiltinCD :
if ( command.arguments() ) {
if (command.arguments().begin()->size() == 1
&& command.arguments().begin()->begin()->value() == "-") {
- if (oldCwd_.expired()) {
+ if (oldCwd_.expired() || ! oldCwd_.lock()->active()) {
oldCwd_ = cwd_;
cwd_ = root().thisptr();
} else
case ParseCommandInfo::BuiltinEXIT :
throw ExitException();
+
+ case ParseCommandInfo::BuiltinHELP :
+ try {
+ GenericNode & node (
+ command.arguments()
+ ? cwd().traverse(
+ boost::make_iterator_range(
+ boost::make_transform_iterator(command.arguments().begin()[0].begin(), TraverseTokens()),
+ boost::make_transform_iterator(command.arguments().begin()[0].end(), TraverseTokens())))
+ : cwd() );
+ node.help(output);
+ output << std::flush;
+ }
+ catch (UnknownNodeNameException &) {
+ output << "invalid path" << std::endl;
+ }
+ break;
}
}
catch (InvalidDirectoryException &) {
output << "invalid directory" << std::endl;
}
+ catch (InvalidCommandException &) {
+ output << "invalid command" << std::endl;
+ }
return true;
}
prefix_ senf::console::DirectoryNode &
-senf::console::Executor::traverseTo(ParseCommandInfo::argument_value_type const & path)
+senf::console::Executor::traverseTo (ParseCommandInfo::argument_value_type const & path)
{
try {
return dynamic_cast<DirectoryNode&>(
throw InvalidDirectoryException();
}
}
+
+prefix_ senf::console::CommandNode &
+senf::console::Executor::traverseToCommand(ParseCommandInfo::CommandPathRange const & path)
+{
+ try {
+ return dynamic_cast<CommandNode &>( cwd().traverse(path) );
+ }
+ catch (std::bad_cast &) {
+ throw InvalidCommandException();
+ }
+ catch (UnknownNodeNameException &) {
+ throw InvalidCommandException();
+ }
+}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_