prefix_ void senf::console::LinkNode::v_help(std::ostream & os)
const
{
- os << "link to ";
follow().help(os);
}
+prefix_ std::string senf::console::LinkNode::v_shorthelp()
+ const
+{
+ return follow().shorthelp();
+}
+
///////////////////////////////////////////////////////////////////////////
//senf::console::DirectoryNode
output << doc_ << "\n";
}
+prefix_ std::string senf::console::DirectoryNode::v_shorthelp()
+ const
+{
+ if (! shortdoc_.empty())
+ return shortdoc_;
+ return doc_.substr(0,doc_.find('\n'));
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::console::detail::NodeTraverser
output << doc_ << "\n";
}
+prefix_ std::string senf::console::SimpleCommandNode::v_shorthelp()
+ const
+{
+ if (! shortdoc_.empty())
+ return shortdoc_;
+ return doc_.substr(0,doc_.find('\n'));
+}
+
prefix_ void senf::console::SimpleCommandNode::v_execute(boost::any & rv, std::ostream & os,
ParseCommandInfo const & command)
const
v_help(output);
}
+prefix_ std::string senf::console::GenericNode::shorthelp()
+ const
+{
+ return v_shorthelp();
+}
+
prefix_ bool senf::console::GenericNode::operator==(GenericNode & other)
const
{
return *this;
}
+prefix_ senf::console::DirectoryNode &
+senf::console::DirectoryNode::shortdoc(std::string const & doc)
+{
+ shortdoc_ = doc;
+ return *this;
+}
+
prefix_ senf::console::DirectoryNode::ptr senf::console::DirectoryNode::thisptr()
{
return boost::static_pointer_cast<DirectoryNode>(shared_from_this());
return *this;
}
+prefix_ senf::console::SimpleCommandNode &
+senf::console::SimpleCommandNode::shortdoc(std::string const & doc)
+{
+ shortdoc_ = doc;
+ return *this;
+}
+
prefix_ senf::console::SimpleCommandNode::ptr senf::console::SimpleCommandNode::thisptr()
{
return boost::static_pointer_cast<SimpleCommandNode>(shared_from_this());
bool active() const; ///< \c true, if node is attached to the root() node
void help(std::ostream & output) const; ///< Write help info to \a output
+ std::string shorthelp() const; ///< Get short (one-line) documentation
ptr thisptr(); ///< Get smart pointer to node
cptr thisptr() const; ///< Get smart pointer to node (const)
#endif
virtual void v_help(std::ostream & output) const = 0;
///< Provide help information
- /**< This member must be implemented in derived classes
- to provide node specific help information. */
+ /**< This member must be implemented in derived classes to
+ provide node specific help information. */
+ virtual std::string v_shorthelp() const = 0;
+ ///< Provide short documentation
+ /**< This member must be implemented in derived classes to
+ provide node specific documentation. */
private:
std::string name_;
explicit LinkNode(GenericNode & node);
virtual void v_help(std::ostream &) const;
+ virtual std::string v_shorthelp() const;
GenericNode::ptr node_;
};
///////////////////////////////////////////////////////////////////////////
DirectoryNode & doc(std::string const & doc); ///< Set node documentation
+ DirectoryNode & shortdoc(std::string const & doc); ///< Set node short documentation
ptr thisptr();
cptr thisptr() const;
private:
void add(GenericNode::ptr node);
virtual void v_help(std::ostream & output) const;
+ virtual std::string v_shorthelp() const;
ChildMap children_;
std::string doc_;
+ std::string shortdoc_;
friend DirectoryNode & root();
};
cptr thisptr() const;
SimpleCommandNode & doc(std::string const & doc);
+ SimpleCommandNode & shortdoc(std::string const & doc);
protected:
SimpleCommandNode(Function const & fn);
private:
virtual void v_help(std::ostream & output) const;
+ virtual std::string v_shorthelp() const;
virtual void v_execute(boost::any & rv, std::ostream & os, ParseCommandInfo const & command)
const;
Function fn_;
std::string doc_;
+ std::string shortdoc_;
};
#ifndef DOXYGEN
completions,
completions+sizeof(completions)/sizeof(completions[0]) );
- p->doc("test doc");
+ p->doc("test doc\nline 2");
std::stringstream ss;
p->help(ss);
- BOOST_CHECK_EQUAL( ss.str(), "test doc\n" );
+ BOOST_CHECK_EQUAL( ss.str(), "test doc\nline 2\n" );
+ BOOST_CHECK_EQUAL( p->shorthelp(), "test doc" );
+ p->doc("");
+ BOOST_CHECK_EQUAL( p->shorthelp(), "" );
+ p->shortdoc("short doc");
+ BOOST_CHECK_EQUAL( p->shorthelp(), "short doc" );
BOOST_CHECK( senf::console::root().remove("dir1") == p );
senf::console::root().remove("dir2");
}
}
+prefix_ std::string senf::console::OverloadedCommandNode::v_shorthelp()
+ const
+{
+ if (!shortdoc_.empty())
+ return shortdoc_;
+ return doc_.substr(0,doc_.find('\n'));
+}
+
prefix_ void senf::console::OverloadedCommandNode::v_execute(boost::any & rv,
std::ostream & os,
ParseCommandInfo const & command)
return *this;
}
+prefix_ senf::console::OverloadedCommandNode &
+senf::console::OverloadedCommandNode::shortdoc(std::string const & doc)
+{
+ shortdoc_ = doc;
+ return *this;
+}
+
prefix_ unsigned
senf::console::OverloadedCommandNode::overloadIndex(CommandOverload const & overload)
{
OverloadedCommandNode & doc(std::string const & doc);
///< Assign global help for all overloads
+ OverloadedCommandNode & shortdoc(std::string const & doc);
+ ///< Assign short documentation for all overloads
unsigned overloadIndex(CommandOverload const & overload);
///< Return the overload index for \a overload
OverloadedCommandNode();
virtual void v_help(std::ostream & output) const;
+ virtual std::string v_shorthelp() const;
virtual void v_execute(boost::any & rv, std::ostream & os, ParseCommandInfo const & command)
const;
Overloads overloads_;
std::string doc_;
+ std::string shortdoc_;
};
/** \brief Basic command overload
node().doc(doc);
}
+prefix_ void senf::console::ParsedCommandAttributorBase::shortDoc(std::string const & doc)
+ const
+{
+ node().shortdoc(doc);
+}
+
///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_
template <class Overload, class Self, class ReturnType>
prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self,ReturnType>::
+shortdoc(std::string const & doc)
+ const
+{
+ this->ParsedCommandAttributorBase::shortDoc(doc);
+ return static_cast<Self const &>(*this);
+}
+
+template <class Overload, class Self, class ReturnType>
+prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self,ReturnType>::
overloadDoc(std::string const & doc)
const
{
}
template <class Overload, class Self>
+prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload, Self, void>::
+shortdoc(std::string const & doc)
+ const
+{
+ this->ParsedCommandAttributorBase::shortDoc(doc);
+ return static_cast<Self const &>(*this);
+}
+
+template <class Overload, class Self>
prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self,void>::
overloadDoc(std::string const & doc)
const
ParsedCommandOverloadBase & overload() const;
void overloadDoc(std::string const & doc) const;
void nodeDoc(std::string const & doc) const;
+ void shortDoc(std::string const & doc) const;
private:
ParsedCommandOverloadBase & overload_;
{
public:
Self doc(std::string const & doc) const; ///< Set documentation for all overloads
+ Self shortdoc(std::string const & doc) const; ///< Set short documentation for all overloads
Self overloadDoc(std::string const & doc) const; ///< Set overload specific documentation
Self formatter(typename Overload::Formatter formatter) const;
///< Set return value formatter
{
public:
Self doc(std::string const & doc) const; ///< Set documentation for all overloads
+ Self shortdoc(std::string const & doc) const; ///< Set short documentation for all overloads
Self overloadDoc(std::string const & doc) const; ///< Set overload specific documentation
protected:
"lux sto ioco. Per Re dono. Copiose reus scitus jus diligens sis scapulare\n"
"Servitium transi." )
+ .shortdoc(
+ "Ops fortunate." )
+
.overloadDoc(
"Lo nam balnearius Opprimo Pennatus, no decentia sui, dicto esse se pulchritudo,\n"
"pupa Sive res indifferenter. Captivo pa." )
boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
BOOST_CHECK_EQUAL( ss.str(), "333\n" "224\n" "Value: foo\n" "Value: \n" );
+
+ BOOST_CHECK_EQUAL( dir("cb").shorthelp(), "Ops fortunate." );
}
{
template <class Variable>
prefix_ senf::console::ConstVariableAttributor<Variable>
+senf::console::ConstVariableAttributor<Variable>::shortdoc(std::string const & doc)
+{
+ queryOverload_.node().shortdoc(doc);
+ return *this;
+}
+
+template <class Variable>
+prefix_ senf::console::ConstVariableAttributor<Variable>
senf::console::ConstVariableAttributor<Variable>::formatter(Formatter formatter)
{
queryOverload_.formatter(formatter);
template <class Variable>
prefix_ typename senf::console::VariableAttributor<Variable>
+senf::console::VariableAttributor<Variable>::shortdoc(std::string const & doc)
+{
+ ConstVariableAttributor<Variable>::shortdoc(doc);
+ return *this;
+}
+
+template <class Variable>
+prefix_ typename senf::console::VariableAttributor<Variable>
senf::console::VariableAttributor<Variable>::formatter(Formatter formatter)
{
ConstVariableAttributor<Variable>::formatter(formatter);
typedef ConstVariableAttributor return_type;
ConstVariableAttributor doc(std::string const & doc);
+ ConstVariableAttributor shortdoc(std::string const & doc);
ConstVariableAttributor formatter(Formatter formatter);
OverloadedCommandNode & node() const; ///< Return the node object
typedef typename ConstVariableAttributor<Variable>::QueryOverload QueryOverload;
VariableAttributor doc(std::string const & doc); ///< Set documentation of the variable
+ VariableAttributor shortdoc(std::string const & doc); ///< Set short documentation
VariableAttributor formatter(Formatter formatter); ///< Set formatter
/**< The \a formatter must be a callable with a signature
compatible with