65 SENF_ASSERT( node_,
"Overload not added to any node yet" );
85 std::string
const &
name,
128 prefix_ void senf::console::OverloadedCommandNode::v_help(std::ostream & os)
131 typedef std::vector<ArgumentDoc> ArgumentDocs;
132 ArgumentDocs argumentDocs;
133 bool haveDocumentedArg (
false);
137 Overloads::const_iterator i (overloads_.begin());
138 Overloads::const_iterator
const i_end (overloads_.end());
140 for (; i != i_end; ++i, ++index) {
142 if (overloads_.size() > 1) os << index <<
"- ";
144 for (
unsigned j (0); j < (*i)->numArguments(); ++j) {
146 (*i)->argumentDoc(j, arg);
151 if (! arg.
name.empty()) os << arg.
name;
152 if (! arg.
type.empty()) os <<
':' << arg.
type;
153 if (arg.
name.empty() && arg.
type.empty()) os <<
"...";
158 ArgumentDocs::iterator k (argumentDocs.begin());
159 ArgumentDocs::iterator
const k_end (argumentDocs.end());
160 for (; k != k_end; ++k)
162 if (! arg.
doc.empty() && k->doc.empty()) {
164 haveDocumentedArg =
true;
169 argumentDocs.push_back(arg);
170 if (! arg.
doc.empty())
171 haveDocumentedArg =
true;
179 if (haveDocumentedArg) {
180 os <<
"\n" "With:\n";
181 ArgumentDocs::const_iterator i (argumentDocs.begin());
182 ArgumentDocs::const_iterator
const i_end (argumentDocs.end());
183 for (; i != i_end; ++i) {
184 if (! i->doc.empty() || ! i->defaultValue.empty()) {
187 << std::string(i->name.length()<8 ? 8-i->name.length() : 0,
' ')
191 if (! i->defaultValue.empty())
192 os <<
" default: " << i->defaultValue <<
'\n';
198 os <<
"\n" << doc_ <<
"\n";
201 Overloads::const_iterator i (overloads_.begin());
202 Overloads::const_iterator
const i_end (overloads_.end());
204 for (; i != i_end; ++i, ++index) {
205 std::string overloadDoc ((*i)->doc());
206 if (! overloadDoc.empty()) {
208 if (overloads_.size() > 1)
209 os <<
"Variant " << index <<
":\n";
210 os << overloadDoc <<
"\n";
216 prefix_ std::string senf::console::OverloadedCommandNode::v_shorthelp()
219 if (!shortdoc_.empty())
222 return doc_.substr(0,doc_.find(
'\n'));
223 for (
auto const & i : overloads_) {
224 std::string overloadDoc (i->doc());
225 if (! overloadDoc.empty())
226 return overloadDoc.substr(0,overloadDoc.find(
'\n'));
231 prefix_ void senf::console::OverloadedCommandNode::v_execute(boost::any & rv,
237 for (
auto const & i : overloads_) {
239 (*i)(rv, os, command);
252 prefix_ unsigned senf::console::SimpleCommandOverload::v_numArguments()
262 prefix_ std::string senf::console::SimpleCommandOverload::v_doc()
268 prefix_ void senf::console::SimpleCommandOverload::v_execute(boost::any & rv,
std::string type
Argument type (string representation)
void argumentDoc(unsigned index, ArgumentDoc &doc) const
Get information on argument index.
OverloadedCommandNode & node() const
Access owning node.
std::string doc
Documentation for this argument.
virtual ~CommandOverload()
boost::intrusive_ptr< CommandOverload > ptr
Command & add(boost::intrusive_ptr< Command > overload)
Add an additional overload.
virtual void v_argumentDoc(unsigned index, ArgumentDoc &doc) const =0
Return argument documentation.
Config/console tree directory node.
unsigned overloadIndex(CommandOverload const &overload)
Return the overload index for overload.
bool hasChild(std::string const &name) const
true, if there is a child with name name
Syntax error parsing command arguments exception.
Command node which allows multiple registered callbacks.
virtual unsigned v_numArguments() const =0
Return the number of arguments.
void operator()(boost::any &rv, std::ostream &os, ParseCommandInfo const &command)
Call the overload.
Single parsed console command.
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
Add node to tree.
std::string defaultValue
Default value (string representation) or empty string.
void execute(boost::any &rv, std::ostream &os, ParseCommandInfo const &command)
Call the overload.
OverloadedCommand public header.
#define SENF_ASSERT(x, comment)
unsigned overloadIndex() const
Get index of overload in it's OverloadedCommandNode.
std::string doc() const
Get overload documentation.
std::string name
Argument name.
unspecified_keyword_type name
Argument name.
static OverloadedCommandNode & insertOverload(DirectoryNode &dir, std::string const &name, CommandOverload::ptr overload)
virtual std::string v_doc() const =0
Return overload documentation.
Documentation for a single argument.
unsigned numArguments() const
Number of arguments this overload takes.
virtual void v_execute(boost::any &rv, std::ostream &os, ParseCommandInfo const &command) const =0
Execute the overload.