66 #include "rnr/rnrconfig.h" 94 static string atname(
"@N@");
118 std::set<string> setOfCmds;
119 std::set<string>::iterator iterHelp;
125 for(i = 1; i < argv.size(); ++i)
127 if( (argv[i] ==
"--brief") || (argv[i] ==
"-b") )
131 else if( (argv[i] ==
"--list") || (argv[i] ==
"-l") )
135 else if( (argv[i] ==
"--usage") || (argv[i] ==
"-u") )
141 setOfCmds.insert(argv[i].s());
148 if( setOfCmds.empty() )
153 for(iterDefs = cli.
begin(); iterDefs != cli.
end(); ++iterDefs)
155 setOfCmds.insert(iterDefs->second.getName());
162 for(iterHelp = setOfCmds.begin();
163 iterHelp != setOfCmds.end();
166 const string &cmdName = *iterHelp;
167 const CmdDef &cmdDef = cli.
at(cmdName);
171 cout <<
"Error: help: No help for command '" << cmdName <<
"'." 189 cout <<
" ---" << endl << endl;
203 cout <<
" " << setOfCmds.size() <<
" commands" << endl;
227 const string &strName,
228 const string &strSyntax,
229 const string &strSynopsis,
230 const string &strLongDesc,
235 if( strName.empty() )
237 os <<
"Error: Command has no name." << endl;
241 if( strSyntax.empty() )
243 os <<
"Error: Command has no extended usage syntax." << endl;
256 os << strName <<
" - " << strSynopsis << endl;
260 for(i = 0; i < usages.size(); ++i)
262 if( !usages[i].empty() )
264 os << usages[i] <<
"\n";
274 len = (ssize_t)strName.size() + 2;
276 os << strName <<
"()";
283 os << strName <<
"()";
287 os <<
"Name\n " << strName;
288 os <<
" - " << strSynopsis;
292 for(i = 0; i < usages.size(); ++i)
294 if( !usages[i].empty() )
296 os <<
" " << usages[i] <<
"\n";
301 if( !strLongDesc.empty() )
303 os <<
"Description\n";
306 size_t wstart, wend, wlen;
309 for(i = 0; i < lines.size(); ++i)
318 for(
size_t j = 0; j < lines[i].size(); )
321 while( isspace(lines[i][j]) && (j < lines[i].size()) )
339 if( j >= lines[i].size() )
347 while( !isspace(lines[i][j]) && (j < lines[i].size()) )
353 wlen = wend - wstart;
356 if( (cursor > 2) && (cursor+wlen >= 80) )
363 cout << lines[i].substr(wstart, wlen);
392 "@N@ [{--brief | -b | --list | -l | --usage | -u}] [<cmd>]"),
394 .synopsis =
"Print command help.",
397 "Print command help. " 398 "If a <cmd> is specified, then only help for that command is " 399 "printed. Otherwise all command help is printed.\n\n" 400 "Mandotory arguments to long options are mandatory for short " 402 "-b, --brief Print only command brief descriptions.\n" 403 "-l, --list Print only command names\n" 404 "-u, --usage Print only command usages (syntax)." 450 .synopsis =
replace(
atname, cmd,
"@N@ command-line interface.")
496 .synopsis =
"Enable/disable backtracing of input line parsing.",
499 "Enable/disable backtracing of input line parsing." 500 "The <onoff> argument is a boolean string whose conversion is " 501 "either true(enable) and false(disable)." Command line interface command add-ons interface.
std::vector< std::string > StringVec
Useful types.
int getUid() const
Get command's unique id.
std::string name
command name
CmdDefMap::const_iterator CmdDefCIter
cmd const iter type
static int execQuit(CommandLine &cli, const CmdExtArgVec &argv)
Execute 'quit' command.
CmdDefCIter begin() const
Return a constant iterator pointing to the first element of the list of command definitions.
std::string synopsis
short command synopsis
std::string longdesc
long command description
void quit()
Mark command-line interface to quit.
const std::string & getSynopsis() const
Return command's synopsis.
CmdDefCIter end() const
Return a constant iterator referring to the past-the-end element of the list of command definitions...
static int execBtEnable(CommandLine &cli, const CmdExtArgVec &argv)
Execute 'backtrace' command.
const int NoUid
Special values.
Of string spaces and their strangian operators.
User available command description structure.
size_t split(const std::string &str, const char delim, StringVec &elems)
Split string.
const CmdDef & at(const int uid) const
Get the command definition with the unique id.
Compiled command definition class.
Command line interface class interface.
std::vector< CmdExtArg > CmdExtArgVec
vector of ext args type
virtual int addCommand(const CmdDesc &desc)
Add a command to the command line interface.
HelpSect
Command help section identifiers.
command name help section
static string atname("@N@")
string to replace by command name
Command line command definition class interface.
int addBtEnableCommand(CommandLine &cli, const std::string &strName="bt")
Add the core 'bt' command to the command-line interface.
void setBtEnable(bool bEnable)
Enable/disable backtracing.
const std::string & getName() const
Return command's name.
const std::string & getLongDesc() const
Return command's long description.
int addHelpCommand(CommandLine &cli, const std::string &strName="help")
Add the core 'help' command to the command-line interface.
Command line core data types.
int printCmdHelp(ostream &os, const string &strName, const string &strSyntax, const string &strSynopsis, const string &strLongDesc, const HelpSect section)
static int execHelp(CommandLine &cli, const CmdExtArgVec &argv)
Execute 'help' command.
command brief description help section
command usage (synopsis) help section
std::string & replace(const std::string &what, const std::string &with, std::string &str)
In-place replace all whats in string with with.
const std::string & getSyntax() const
Return command's syntax usage.
std::string syntax
parsable command extended usage syntax
all commond help sections
int addQuitCommand(CommandLine &cli, const std::string &strName="quit")
Add the core 'quit' command to the command-line interface.