senf::console::ScopedDirectory<> chroot;
senf::console::root().add("chroot", chroot);
- root.mkdir("dir1").add("fun1", fty::Command(&fun1));
+ root.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
root.add("fun2", fty::Command(&fun2));
- chroot.mkdir("dir1").add("fun1", fty::Command(&fun1));
+ chroot.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
chroot.add("fun2", fty::Command(&fun2));
TempFile cfg ("test.cfg");
senf::console::ScopedDirectory<> dir2;
senf::console::root().add("dir2", dir2);
- dir2.mkdir("dir3").add("fun2", fty::Command(&fun2));
+ dir2.add("dir3",fty::Directory()).add("fun2", fty::Command(&fun2));
dir2.add("fun1", fty::Command(&fun1));
{
senf::console::ScopedDirectory<> dir2;
dir1.add("dir2", dir2);
- dir2.mkdir("dir3").add("fun2", fty::Command(&fun2));
+ dir2.add("dir3",fty::Directory()).add("fun2", fty::Command(&fun2));
dir2.add("fun1", fty::Command(&fun1));
senf::console::ScopedDirectory<> dir4;
senf::console::root().add("dir4", dir4);
- dir4.link("link1", dir2);
+ dir4.add("link1", fty::Link(dir2));
{
senf::console::ConfigFile cfg (cfgf.name(), dir4);
{
namespace fty = senf::console::factory;
- senf::console::root().mkdir("dir1").mkdir("dir3");
- senf::console::root().mkdir("dir2").doc("Helptext").add("test",fty::Command(&testCommand));
+ senf::console::root().add("dir1",fty::Directory()).add("dir3",fty::Directory());
+ senf::console::root().add("dir2",fty::Directory()).doc("Helptext").add("test",fty::Command(&testCommand));
senf::console::Executor executor;
senf::console::CommandParser parser;
{
namespace fty = senf::console::factory;
- senf::console::root().mkdir("dir1").mkdir("dir3");
- senf::console::root().mkdir("dir2").doc("Helptext").add("test", fty::Command(&testCommand));
+ senf::console::root().add("dir1",fty::Directory()).add("dir3",fty::Directory());
+ senf::console::root().add("dir2",fty::Directory().doc("Helptext"))
+ .add("test", fty::Command(&testCommand));
senf::console::Executor executor;
senf::console::CommandParser parser;
{
namespace fty = senf::console::factory;
- senf::console::root().mkdir("dir1").mkdir("dir3");
- senf::console::root().mkdir("dir2").doc("Helptext").add("test",fty::Command(&testCommand));
+ senf::console::root().add("dir1",fty::Directory()).add("dir3",fty::Directory());
+ senf::console::root().add("dir2",fty::Directory().doc("Helptext"))
+ .add("test",fty::Command(&testCommand));
senf::console::Executor executor;
senf::console::CommandParser parser;
{
namespace fty = senf::console::factory;
- senf::console::root().mkdir("tdir1").mkdir("dir3");
- senf::console::root().mkdir("dir2").doc("Helptext").add("test",fty::Command(&testCommand));
+ senf::console::root().add("tdir1",fty::Directory()).add("dir3",fty::Directory());
+ senf::console::root().add("dir2",fty::Directory().doc("Helptext"))
+ .add("test",fty::Command(&testCommand));
senf::console::Executor executor;
executor
return getCommand(name);
}
-prefix_ senf::console::DirectoryNode &
-senf::console::DirectoryNode::mkdir(std::string const & name)
-{
- return add(name, create());
-}
-
-prefix_ senf::console::DirectoryNode &
-senf::console::DirectoryNode::provideDirectory(std::string const & name)
-{
- return hasChild(name) ? getDirectory(name) : mkdir(name);
-}
-
prefix_ senf::console::DirectoryNode::ChildrenRange senf::console::DirectoryNode::children()
const
{
children_.lower_bound(s + "\xff"));
}
-prefix_ void senf::console::DirectoryNode::link(std::string const & name, GenericNode & target)
-{
- add(name, LinkNode::create(target));
-}
-
prefix_ senf::console::DirectoryNode::DirectoryNode()
{}
}
///////////////////////////////////////////////////////////////////////////
+
+prefix_ senf::console::DirectoryNode & senf::console::provideDirectory(DirectoryNode & dir,
+ std::string const & name)
+{
+ return dir.hasChild(name) ? dir.getDirectory(name) : dir.add(name, factory::Directory());
+}
+
+
+///////////////////////////////////////////////////////////////////////////
// senf::console::factory::SimpleCommand
prefix_ senf::console::factory::SimpleCommand::SimpleCommand(SimpleCommandNode::Function fn)
return *this;
}
+///////////////////////////////////////////////////////////////////////////
+// senf::console::factory::Directory
+
+prefix_ senf::console::factory::Directory::Directory()
+ : node_ (DirectoryNode::create())
+{}
+
+prefix_ senf::console::DirectoryNode &
+senf::console::factory::Directory::create(DirectoryNode & dir, std::string const & name)
+ const
+{
+ return dir.add(name, node_);
+}
+
+prefix_ senf::console::factory::Directory const &
+senf::console::factory::Directory::doc(std::string const & doc)
+ const
+{
+ node_->doc(doc);
+ return *this;
+}
+
+prefix_ senf::console::factory::Directory const &
+senf::console::factory::Directory::shortdoc(std::string const & doc)
+ const
+{
+ node_->shortdoc(doc);
+ return *this;
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::console::factory::Link
+
+prefix_ senf::console::factory::Link::Link(GenericNode & target)
+ : node_ (LinkNode::create(target))
+{}
+
+prefix_ senf::console::LinkNode & senf::console::factory::Link::create(DirectoryNode & dir,
+ std::string const & name)
+ const
+{
+ return dir.add(name, node_);
+}
+
///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_
SomeClass() : dir(this)
{
+ namespace fty = senf::console::factory;
// You may document the directory here or later when adding it to the tree
dir.doc("Manager for something");
// Add a member function (the pointer-to-member is automatically bound to this instance)
- dir.add("member", &SomeClass::member)
- .doc("Do the member operation");
+ dir.add("member", fty::Command(this, &SomeClass::member)
+ .doc("Do the member operation"));
}
void member(std::ostream & os, senf::console::ParseCommandInfo const & command)
int main(int, char**)
{
+ namespace fty = senf::console::factory;
+
// Provide global documentation
senf::console::root()
.doc("This is someServer server");
// Add a new directory to the root and document it. All the mutators return the node object
// itself so operations can be chained.
senf::console::DirectoryNode & mydir ( senf::console::root()
- .mkdir("myserver")
- .doc("My server specific directory"));
+ .add("myserver", fty::Directory()
+ .doc("My server specific directory")));
// Add a command to that directory
- mydir.add("mycommand", &mycommand)
+ mydir.add("mycommand", fty::Command(&mycommand)
.doc("mycommand <foo> [<bar>]\n\n"
- "If <bar> is given, flurgle the <foo>, otherwise burgle it");
+ "If <bar> is given, flurgle the <foo>, otherwise burgle it"));
// Create a SomeClass instance and add it's directory.
SomeClass someClass;
\throws std::bad_cast if the child \a name is not a
command node. */
- DirectoryNode & mkdir(std::string const & name);
- ///< Create sub-directory node
- DirectoryNode & provideDirectory(std::string const & name);
- ///< Return subdirectory, possibly creating it
-
ChildrenRange children() const; ///< Return iterator range over all children.
/**< The returned range is sorted by child name. */
///< Return iterator range of completions for \a s
/**< The returned range is sorted by child name. */
- void link(std::string const & name, GenericNode & target);
- ///< Create a child node which is a link to target. \a s
- /**< The new link node will be a child of the node for which this member function is called. */
-
///\}
///////////////////////////////////////////////////////////////////////////
std::string shortdoc_;
};
+ DirectoryNode & provideDirectory(DirectoryNode & dir, std::string const & name);
+
#ifndef DOXYGEN
namespace factory {
SimpleCommandNode::ptr node_;
};
+ class Directory
+ : public detail::NodeFactory
+ {
+ public:
+ typedef DirectoryNode node_type;
+ typedef DirectoryNode & result_type;
+
+ Directory();
+
+ DirectoryNode & create(DirectoryNode & dir, std::string const & name) const;
+
+ Directory const & doc(std::string const & doc) const;
+ Directory const & shortdoc(std::string const & doc) const;
+
+ private:
+ DirectoryNode::ptr node_;
+ };
+
+ class Link
+ : public detail::NodeFactory
+ {
+ public:
+ typedef LinkNode node_type;
+ typedef LinkNode & result_type;
+
+ explicit Link(GenericNode & target);
+
+ LinkNode & create(DirectoryNode & dir, std::string const & name) const;
+
+ private:
+ LinkNode::ptr node_;
+ };
+
}
#endif
SENF_AUTO_UNIT_TEST(genericNode)
{
+ namespace fty = senf::console::factory;
+
senf::console::GenericNode & node (
- senf::console::root().mkdir("dir1").mkdir("dir2").doc("help info"));
+ senf::console::root()
+ .add("dir1", fty::Directory())
+ .add("dir2", fty::Directory().doc("help info")));
senf::console::GenericNode::weak_ptr wp (node.thisptr());
BOOST_CHECK_EQUAL( node.name(), "dir2" );
SENF_AUTO_UNIT_TEST(directoryNode)
{
+ namespace fty = senf::console::factory;
+
senf::console::DirectoryNode::ptr p (senf::console::DirectoryNode::create());
BOOST_CHECK( & senf::console::root().add("dir1", p) == p.get() );
BOOST_CHECK_THROW( senf::console::root()["fn"], std::bad_cast );
BOOST_CHECK( &senf::console::root().get("dir1") == p.get() );
- senf::console::root().mkdir("dir2").mkdir("dir3");
+ senf::console::root()
+ .add("dir2", fty::Directory())
+ .add("dir3", fty::Directory());
char const * const children[] = { "dir1", "dir2", "fn", "sys" };
BOOST_CHECK_EQUAL_COLLECTIONS(
boost::make_transform_iterator(senf::console::root().children().begin(),
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::root()["dir2"].add("dir4", fty::Directory());
+ senf::console::root()["dir2"].add("link", fty::Link(*p));
+ senf::console::root()["dir2"]["dir4"].add("link", fty::Link(senf::console::root()));
senf::console::dump(ss, senf::console::root()["dir2"]);
BOOST_CHECK_EQUAL( ss.str(),
"dir3/\n"
SENF_AUTO_UNIT_TEST(linkNode)
{
- senf::console::root().mkdir("dir1");
- senf::console::root().link("link1", senf::console::root()["dir1"]);
+ namespace fty = senf::console::factory;
+
+ senf::console::root().add("dir1", fty::Directory());
+ senf::console::root().add("link1", fty::Link(senf::console::root()["dir1"]));
BOOST_CHECK( senf::console::root()["dir1"] == senf::console::root()["link1"] );
SENF_AUTO_UNIT_TEST(factory)
{
namespace fty = senf::console::factory;
+
senf::console::root().add("fn1", fty::SimpleCommand(&callback));
senf::console::root().add("fn2", fty::SimpleCommand(Functor()));
namespace fty = senf::console::factory;
senf::console::DirectoryNode & dir (
- senf::console::root()["test"].mkdir("dircb"));
+ senf::console::root()["test"].add("dircb", fty::Directory()));
dir.add("cb1", fty::Command(&cb1));
return dir.thisptr();
}
senf::console::ScopedDirectory<> root;
senf::console::root().add("root", root);
- root.mkdir("dir1").add("fun1", fty::Command(&fun1));
+ root.add("dir1", fty::Directory()).add("fun1", fty::Command(&fun1));
root.add("fun2", fty::Command(&fun2));
- root.mkdir("name-with-dashes").add("fun-2", fty::Command(&fun2));
+ root.add("name-with-dashes", fty::Directory()).add("fun-2", fty::Command(&fun2));
{
char const * argv[] = { "", "--dir1-fun1=foo","--fun2" };
return node().get(name);
}
-prefix_ senf::console::DirectoryNode &
-senf::console::ScopedDirectoryBase::mkdir(std::string const & name)
-{
- return node().mkdir(name);
-}
-
-prefix_ void senf::console::ScopedDirectoryBase::link(std::string const & name,
- GenericNode & target)
-{
- return node().link(name, target);
-}
-
prefix_ senf::console::DirectoryNode::ChildrenRange
senf::console::ScopedDirectoryBase::children()
const
CommandNode & getCommand(std::string const & name) const;
CommandNode & operator()(std::string const & name) const;
GenericNode & get(std::string const & name) const;
- DirectoryNode & mkdir(std::string const & name);
- void link(std::string const & name, GenericNode & node);
DirectoryNode::ChildrenRange children() const;
DirectoryNode & doc(std::string const & doc);
{
senf::console::ScopedDirectory<> dir;
senf::console::root().add("dir", dir);
- dir.mkdir("foo");
+ dir.add("foo",fty::Directory());
dir.add("cb", fty::Command(&callback));
BOOST_CHECK( &dir["foo"] == &dir.get("foo") );
BOOST_CHECK( &dir("cb") == &dir.get("cb") );
#include <senf/Scheduler/Scheduler.hh>
namespace kw = senf::console::kw;
+namespace fty = senf::console::factory;
void echo(std::ostream & output, senf::console::ParseCommandInfo const & command)
{
TestObject()
: dir(this)
{
- dir.add("vat", &TestObject::vat)
- .arg("vat", "VAT in %", kw::default_value = 19)
- .arg("amount", "Amount including VAT")
- .doc("Returns the amount of {vat}-% VAT included in {amount}");
+ dir.add("vat", fty::Command(this, &TestObject::vat)
+ .arg("vat", "VAT in %", kw::default_value = 19)
+ .arg("amount", "Amount including VAT")
+ .doc("Returns the amount of {vat}-% VAT included in {amount}") );
}
double vat (int vat, double amount)
.doc("This is the console test application");
senf::console::root()
- .mkdir("console")
- .doc("Console settings");
+ .add("console",fty::Directory()
+ .doc("Console settings"));
senf::console::DirectoryNode & serverDir (
senf::console::root()
- .mkdir("server")
- .doc("server commands") );
+ .add("server",fty::Directory()
+ .doc("server commands")));
senf::console::ScopedDirectory<> testDir;
senf::console::root()
.doc("Test functions");
senf::console::root()["console"]
- .add("showlog", &enableLogging)
- .doc("Enable display of log messages on the current console");
+ .add("showlog", fty::Command(&enableLogging)
+ .doc("Enable display of log messages on the current console"));
- senf::console::root().link("sl", senf::console::root()["console"]("showlog"));
+ senf::console::root().add("sl", fty::Link(senf::console::root()["console"]("showlog")));
serverDir
- .add("shutdown", &shutdownServer)
- .doc("Terminate server application");
+ .add("shutdown", fty::Command(&shutdownServer)
+ .doc("Terminate server application"));
testDir
- .add("echo", &echo)
- .doc("Example of a function utilizing manual argument parsing");
+ .add("echo", fty::Command(&echo)
+ .doc("Example of a function utilizing manual argument parsing"));
TestObject test;
testDir
.add("extra", test.dir)
.doc("Example of an instance directory");
- senf::console::root().link("ex", test.dir);
+ senf::console::root().add("ex", fty::Link(test.dir));
senf::console::Server::start( senf::INet4SocketAddress(23232u) )
.name("testServer");