X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FExecutor.hh;h=92a2dfe218bfd8c7dfe367294ade2b8094276aee;hb=1b1d76302a5d61e918ef71f1c8e11f80ac1262e2;hp=be6f15f16f0d72f3d54c394a538d65d1b149d243;hpb=5e9e6057a4e5c1241ff3f1b75b0f797eb570725d;p=senf.git diff --git a/Console/Executor.hh b/Console/Executor.hh index be6f15f..92a2dfe 100644 --- a/Console/Executor.hh +++ b/Console/Executor.hh @@ -38,20 +38,33 @@ namespace senf { namespace console { - /** \brief + /** \brief Execute config/console commands + + The Executor interprets parsed config/console commands and executes them. It manages the + current execution context (current directory, directory stack and so on). + + The executor is normally called directly by the parser callback for each command. + + Executing the built-in 'exit' command will throw Executor::ExitException. This exception + (which is not derived from std::exception since it's not a real exception) must be handled + by the caller. + + All directories are managed using weak pointers. If any of the directories expires (current + directory, directory stack, last directory) it will be replaced with the root + directory. Directories expire when they are destructed or when they are detached from the + config tree root node. */ class Executor : boost::noncopyable { SENF_LOG_CLASS_AREA(); - SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE ); + SENF_LOG_DEFAULT_LEVEL( senf::log::VERBOSE ); public: /////////////////////////////////////////////////////////////////////////// // Types - typedef boost::iterator_range< ParseCommandInfo::argument_iterator> Arguments; - - struct ExitException {}; // NOT derived from std::exception ! + /// Thrown by built-in 'exit' command + struct ExitException {}; /////////////////////////////////////////////////////////////////////////// //\/name Structors and default members @@ -62,17 +75,53 @@ namespace console { ///\} /////////////////////////////////////////////////////////////////////////// - bool operator()(ParseCommandInfo const & command, std::ostream & output); - DirectoryNode & cwd() const; + void execute(std::ostream & output, ParseCommandInfo const & command); + ///< Execute command + /**< Output will be written to \a output. + Same as operator()(). */ + + void operator()(std::ostream & output, ParseCommandInfo const & command); + ///< Execute command + /**< Output will be written to \a output. + Same as execute(). */ + DirectoryNode & cwd() const; ///< Current working directory + + bool autocd() const; ///< Get current autocd status + /**< if autocd is enabled, specifying a directory name as + command will cd to that directory. Disabled by + default (but enabled automatically by the interactive + console). */ + Executor & autocd(bool v); ///< Set autocd status + /**< \see autocd() */ + + bool autocomplete() const; ///< Get current autocomplete status + /**< if autocomplete is enabled, path components which can + be uniquely completed will be completed + automatically. Disabled by default (but enabled + automatically by the interactive console) void + autocomplete(bool v). */ + + Executor & autocomplete(bool v); ///< Set autocomplete status + /**< \see autocomplete() */ protected: private: - bool chdir(ParseCommandInfo::argument_value_type const & path); + GenericNode & traverseNode(ParseCommandInfo::argument_value_type const & path); + GenericNode & traverseCommand(ParseCommandInfo::CommandPathRange const & path); + DirectoryNode & traverseDirectory(ParseCommandInfo::argument_value_type const & path); + + struct InvalidPathException {}; + struct InvalidDirectoryException {}; + struct InvalidCommandException {}; DirectoryNode::weak_ptr cwd_; + DirectoryNode::weak_ptr oldCwd_; typedef std::vector DirStack; DirStack dirstack_; + + bool autocd_; + bool autocomplete_; };