Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdHelp Class Reference

Help command. More...

Inheritance diagram for DynaShellCmdHelp:
DynaShellCmd

Public Member Functions

void Exec (DynaShell &shell, int argc, char *argv[])
 Print help. More...
 
virtual char * TabCompletion (DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
 Command tab completion generator. More...
 
- Public Member Functions inherited from DynaShellCmd
 DynaShellCmd (int nArgCntMin=0, int nArgCntMax=0)
 Default constructor.
 
virtual ~DynaShellCmd ()
 Default destructor.
 
const char * GetCmdName ()
 Get dynamixel shell command name. More...
 
const char * GetCmdHelpBrief ()
 Get shell command name brief description. More...
 
virtual void PrintHelp (int indent=0, int width=80)
 Print command help with the description aligned at the given indentation. More...
 
int GetPublishedLevel () const
 
const char * GetPublishedName () const
 
int SetPublishedInfo (int nLevel, const char *sParent=NULL)
 
virtual bool ChkArgCnt (DynaShell &shell, int argc)
 Check that the argument count is within the class (min,max). More...
 
bool ChkArgCnt0 (DynaShell &shell, int argc)
 Check that the argument count is zero. More...
 
bool ChkArgCntEQ (DynaShell &shell, int argc, int eq)
 Check that the argument count is equal to the required. More...
 
bool ChkArgCntGE (DynaShell &shell, int argc, int min)
 Check argument count against minimum required. More...
 
bool ChkArgCntLE (DynaShell &shell, int argc, int max)
 Check argument count against maximum allowed. More...
 
bool ChkComm (DynaShell &shell)
 Check that Dynamixel communication exists and is open. More...
 
bool ChkChain (DynaShell &shell)
 Check that the servo chain exists. More...
 
bool ChkChainNotEmpty (DynaShell &shell)
 Check that the servo chain exists and is not empty. More...
 
bool ChkChainHasServo (DynaShell &shell, int nServoId)
 Check that the given servo is present in the chain. More...
 
bool ChkChainIsMasterServo (DynaShell &shell, int nServoId)
 Check that the given servo is a master. More...
 
bool ToInt (DynaShell &shell, const char *sArg, int *pVal)
 Convert command argument to integer. More...
 
bool ToUInt (DynaShell &shell, const char *sArg, uint_t *pVal)
 Convert command argument to unsigned integer. More...
 
bool ToDouble (DynaShell &shell, const char *sArg, double *pVal)
 Convert command argument to double. More...
 
bool ToBool (DynaShell &shell, const char *sArg, bool *pVal)
 Convert command argument to boolean. More...
 

Protected Member Functions

void PrintHelpWordList (DynaShell &shell, ShCmdMap &cmdMap)
 Print help list of words. More...
 
void PrintHelpSummaryList (DynaShell &shell, ShCmdMap &cmdMap)
 Print help summary list. More...
 
ShCmdNodeMatchHelp (DynaShell &shell, int argc, char *argv[], ShCmdMap &cmdMap)
 Match command. More...
 
- Protected Member Functions inherited from DynaShellCmd
virtual void PrintSynopses (int indent, int width)
 Print synsopses. More...
 
virtual void PrintBlock (int col, int indent, int width, const char *sText)
 Print a block of indented text of width. More...
 
virtual void PrintDelim (int width, const char cDelim)
 
char * eow (const char *s)
 Find end of word. More...
 

Additional Inherited Members

- Protected Attributes inherited from DynaShellCmd
const char * m_sCmdName
 command name
 
const char * m_sCmdHelpBrief
 command help brief
 
const char * m_sCmdHelpArgs
 command help arguments
 
const char * m_sCmdHelpDesc
 command help description
 
const int m_nArgCntMin
 minimum argument count
 
const int m_nArgCntMax
 maximum argument count (0 if not max)
 
int m_nPubLevel
 command's published level (depth)
 
char * m_sPubName
 command's published name
 

Detailed Description

Help command.

Definition at line 117 of file dynashell_cmd_core.cxx.

Member Function Documentation

void DynaShellCmdHelp::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Print help.

Parameters
shellDynamixel shell.
argcCommand argument count.
argvArray of arguments.

Implements DynaShellCmd.

Definition at line 150 of file dynashell_cmd_core.cxx.

References DynaShell::Error(), ShCmdNode::GetCmd(), ShCmdNode::GetMap(), DynaShell::GetRootCmds(), ShCmdNode::IsCmd(), ShCmdNode::IsMap(), DynaShellCmd::PrintHelp(), and TRY.

151  {
152  ShCmdNode cmdNode;
153 
154  TRY( ChkArgCnt(shell, argc) );
155 
156  // print root command list
157  if( argc == 0 )
158  {
159  //PrintHelpWordList(shell, shell.GetRootCmds());
160  PrintHelpSummaryList(shell, shell.GetRootCmds());
161  printf("\n");
162  return;
163  }
164 
165  cmdNode = MatchHelp(shell, argc, argv, shell.GetRootCmds());
166 
167  // print command object list
168  if( cmdNode.IsMap() )
169  {
170  // PrintHelpWordList(shell, *cmdNode.GetMap());
171  PrintHelpSummaryList(shell, *cmdNode.GetMap());
172  printf("\n");
173  }
174 
175  // print long help.
176  else if( cmdNode.IsCmd() )
177  {
178  cmdNode.GetCmd()->PrintHelp();
179  printf("\n");
180  }
181 
182  // print error 1
183  else if( argc == 1 )
184  {
185  shell.Error("help: Unknown command \"%s\".", argv[0]);
186  }
187 
188  // or print error 2
189  else
190  {
191  shell.Error("help: Unknown command \"%s %s\".", argv[0], argv[1]);
192  }
193  }
ShCmdMap * GetMap()
Get map object.
Definition: dynashell.h:206
DynaShellCmd * GetCmd()
Get command object.
Definition: dynashell.h:196
ShCmdNode & MatchHelp(DynaShell &shell, int argc, char *argv[], ShCmdMap &cmdMap)
Match command.
void PrintHelpSummaryList(DynaShell &shell, ShCmdMap &cmdMap)
Print help summary list.
ShCmdMap & GetRootCmds()
Definition: dynashell.h:446
virtual void PrintHelp(int indent=0, int width=80)
Print command help with the description aligned at the given indentation.
bool IsMap()
Test if node type is map of commands.
Definition: dynashell.h:250
virtual bool ChkArgCnt(DynaShell &shell, int argc)
Check that the argument count is within the class (min,max).
#define TRY(boolexpr,...)
Try boolean expression.
Definition: dynashell_cmd.h:89
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
Shell command node class.
Definition: dynashell.h:119
bool IsCmd()
Test if node type is shell command.
Definition: dynashell.h:243
ShCmdNode& DynaShellCmdHelp::MatchHelp ( DynaShell shell,
int  argc,
char *  argv[],
ShCmdMap cmdMap 
)
inlineprotected

Match command.

Parameters
shellDynamixel shell.
argcCommand argument count.
argvArray of arguments.
cmdMapCommand map to search.
Returns
Shell command node.

Definition at line 286 of file dynashell_cmd_core.cxx.

References DynaShell::Error().

290  {
291  static ShCmdNode cmdNull;
292 
293  ShCmdMap::iterator iter1, iter2;
294  char *sPattern;
295  const char *sCmdName1, *sCmdName2;
296  size_t n;
297 
298  if( argc == 0 )
299  {
300  return cmdNull;
301  }
302 
303  sPattern = argv[0];
304 
305  n = strlen(sPattern);
306 
307  // find command
308  for(iter1=cmdMap.begin(); iter1!=cmdMap.end(); iter1++)
309  {
310  sCmdName1 = iter1->first;
311  if( !strncmp(sPattern, sCmdName1, n) )
312  {
313  break;
314  }
315  }
316 
317  // no matching command found
318  if( iter1 == cmdMap.end() )
319  {
320  return cmdNull;
321  }
322 
323  // verify uniqueness
324  for(iter2=cmdMap.begin(); iter2!=cmdMap.end(); iter2++)
325  {
326  if( iter2 == iter1 )
327  {
328  continue;
329  }
330 
331  sCmdName2 = iter2->first;
332 
333  // another match
334  if( !strncmp(sPattern, sCmdName2, n) )
335  {
336  shell.Error("help: %s: (Sub)Command not unique: Matches %s %s ...",
337  sPattern, sCmdName1, sCmdName2);
338  return cmdNull;
339  }
340  }
341 
342  if( argc == 1 )
343  {
344  return iter1->second;
345  }
346  else if( (argc == 2) && iter1->second.IsMap() )
347  {
348  return MatchHelp(shell, argc-1, argv+1, *iter1->second.GetMap());
349  }
350  else
351  {
352  return cmdNull;
353  }
354  }
ShCmdNode & MatchHelp(DynaShell &shell, int argc, char *argv[], ShCmdMap &cmdMap)
Match command.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
Shell command node class.
Definition: dynashell.h:119
void DynaShellCmdHelp::PrintHelpSummaryList ( DynaShell shell,
ShCmdMap cmdMap 
)
inlineprotected

Print help summary list.

Parameters
shellDynamixel shell.
cmdMapCommand map to print.

Definition at line 266 of file dynashell_cmd_core.cxx.

267  {
268  ShCmdMap::iterator iter;
269 
270  for(iter=cmdMap.begin(); iter!=cmdMap.end(); iter++)
271  {
272  printf("%15s - %s\n", iter->first, iter->second.GetMapBrief().c_str());
273  }
274  }
void DynaShellCmdHelp::PrintHelpWordList ( DynaShell shell,
ShCmdMap cmdMap 
)
inlineprotected

Print help list of words.

Parameters
shellDynamixel shell.
cmdMapCommand map to print.

Definition at line 248 of file dynashell_cmd_core.cxx.

249  {
250  ShCmdMap::iterator iter;
251 
252  for(iter=cmdMap.begin(); iter!=cmdMap.end(); iter++)
253  {
254  printf("%s ", iter->first);
255  }
256 
257  printf("\n");
258  }
virtual char* DynaShellCmdHelp::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes <group> [object]

Parameters
shellDynamixel shell.
sTextPartial text string to complete.
uTextLenLength of text.
nStateGenerator state. If FIRST, then initialize any statics.
sContextGenerator context (i.e. canonical command path).
Returns
If a first/next match is made, return allocated completed match.
Otherwise return NULL.

Reimplemented from DynaShellCmd.

Definition at line 210 of file dynashell_cmd_core.cxx.

References DynaShell::CmdListGenerator().

215  {
216  size_t uCmdLen = strlen(m_sPubName);
217  const char *sSubContext;
218 
219  // this case should not happen
220  if( strlen(sContext) < uCmdLen )
221  {
222  return NULL;
223  }
224 
225  // "help"
226  else if( strlen(sContext) == uCmdLen )
227  {
228  sSubContext = "";
229  }
230 
231  // "help group "
232  else
233  {
234  sSubContext = sContext+uCmdLen+1;
235  }
236 
237  return shell.CmdListGenerator(0, sText, uTextLen, nState, sSubContext);
238  }
char * CmdListGenerator(int nUid, const char *sText, size_t uTextLen, int nState, const char *sContext)
Command list generator function.
Definition: dynashell.cxx:319
char * m_sPubName
command&#39;s published name

The documentation for this class was generated from the following file: