appkit  1.5.1
RoadNarrows Robotics Application Kit
CmdAddOns.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_appkit
8 //
9 // File: CmdAddOns.h
10 //
11 /*! \file
12  *
13  * \brief Command line interface command add-ons interface.
14  *
15  * \author Robin Knight (robin.knight@roadnarrows.com)
16  *
17  * \par Copyright
18  * \h_copy 2016-2017. RoadNarrows LLC.\n
19  * http://www.roadnarrows.com\n
20  * All Rights Reserved
21  *
22  * \par License:
23  * MIT
24  */
25 /*
26  * @EulaBegin@
27  *
28  * Permission is hereby granted, without written agreement and without
29  * license or royalty fees, to use, copy, modify, and distribute this
30  * software and its documentation for any purpose, provided that
31  * (1) The above copyright notice and the following two paragraphs
32  * appear in all copies of the source code and (2) redistributions
33  * including binaries reproduces these notices in the supporting
34  * documentation. Substantial modifications to this software may be
35  * copyrighted by their authors and need not follow the licensing terms
36  * described here, provided that the new terms are clearly indicated in
37  * all files where they apply.
38  *
39  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
40  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
41  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
42  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
43  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
44  * THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
47  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
48  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
49  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
50  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
51  *
52  * @EulaEnd@
53  */
54 ////////////////////////////////////////////////////////////////////////////////
55 
56 #ifndef _RNR_CMD_ADD_ONS_H
57 #define _RNR_CMD_ADD_ONS_H
58 
59 #include <unistd.h>
60 #include <stdlib.h>
61 
62 #include <iostream>
63 #include <sstream>
64 #include <string>
65 #include <vector>
66 
67 #include "rnr/rnrconfig.h"
68 #include "rnr/log.h"
69 
70 #include "rnr/appkit/CmdDef.h"
71 #include "rnr/appkit/CommandLine.h"
72 
73 /*!
74  * \brief RoadNarrows Robotics
75  */
76 namespace rnr
77 {
78  /*!
79  * \brief Commands
80  */
81  namespace cmd
82  {
83  /*!
84  * \brief Add-Ons
85  */
86  namespace addons
87  {
88  //------------------------------------------------------------------------
89  // Help Command Add-On
90  //------------------------------------------------------------------------
91 
92  /*!
93  * \brief Command help section identifiers.
94  */
95  enum HelpSect
96  {
97  HelpSectAll, ///< all commond help sections
98  HelpSectName, ///< command name help section
99  HelpSectBrief, ///< command brief description help section
100  HelpSectUsage ///< command usage (synopsis) help section
101  };
102 
103  /*!
104  * \brief Print help for a command convenience function.
105  *
106  * \param os Output stream.
107  * \param cmddef Command definition.
108  * \param section Help section.
109  *
110  * \return OK(0) on success, negative value on failure.
111  */
112  extern int printCmdHelp(std::ostream &os,
113  const CmdDef &cmddef,
114  const HelpSect section = HelpSectAll);
115 
116  /*!
117  * \brief Print help for a command convenience function.
118  *
119  * \param os Output stream.
120  * \param desc Command description.
121  * \param section Help section.
122  *
123  * \return OK(0) on success, negative value on failure.
124  */
125  extern int printCmdHelp(std::ostream &os,
126  const CmdDesc &desc,
127  const HelpSect section = HelpSectAll);
128 
129  /*!
130  * \brief Print help for a command convenience function.
131  *
132  * \param os Output stream.
133  * \param strName Command name.
134  * \param strSyntax Command usage syntax.
135  * \param strSynopsis Command short synopsis.
136  * \param strLongDesc Command long description.
137  * \param section Help section.
138  *
139  * \return OK(0) on success, negative value on failure.
140  */
141  extern int printCmdHelp(std::ostream &os,
142  const std::string &strName,
143  const std::string &strSyntax,
144  const std::string &strSynopsis,
145  const std::string &strLongDesc,
146  const HelpSect section = HelpSectAll);
147 
148  /*!
149  * \brief Add the core 'help' command to the command-line interface.
150  *
151  * Syntax: help [{--brief | -b | --list | -l | --usage | -u}] [<cmd>]
152  *
153  * The help command will print help for the given help sections for the
154  * given command names to cout.
155  *
156  * Any relevant command data is applied to the command line interface
157  * "core" data section.
158  *
159  * The name of the command may be overridded, but the syntax and
160  * semantics cannot.
161  *
162  * \param cli Command-line interface.
163  * \param strName Name of the command.
164  *
165  * \return On success, returns command's assigned unique id.
166  * Otherwise NoUid is returned.
167  */
168  int addHelpCommand(CommandLine &cli, const std::string &strName = "help");
169 
170 
171  //------------------------------------------------------------------------
172  // Quit Command Add-On
173  //------------------------------------------------------------------------
174 
175  /*!
176  * \brief Add the core 'quit' command to the command-line interface.
177  *
178  * Syntax: quit
179  *
180  * The quit command will disable anymore execution of the command line.
181  * It is up to the application to terminate by querying the command line
182  * ok() method.
183  *
184  * Any relevant command data is applied to the command line interface
185  * "core" data section.
186  *
187  * The name of the command may be overridded, but the syntax and
188  * semantics cannot.
189  *
190  * \param cli Command-line interface.
191  * \param strName Name of the command.
192  *
193  * \return On success, returns command's assigned unique id.
194  * Otherwise NoUid is returned.
195  */
196  int addQuitCommand(CommandLine &cli, const std::string &strName = "quit");
197 
198 
199  //------------------------------------------------------------------------
200  // Backtrace Enable Command Add-On
201  //------------------------------------------------------------------------
202 
203  /*!
204  * \brief Add the core 'bt' command to the command-line interface.
205  *
206  * Syntax: bt <onoff>
207  *
208  * The bt command enables/disables backtracing of input line parsing.
209  * The trace is written to cerr.
210  *
211  * Any relevant command data is applied to the command line interface
212  * "core" data section.
213  *
214  * The name of the command may be overridded, but the syntax and
215  * semantics cannot.
216  *
217  * \param cli Command-line interface.
218  * \param strName Name of the command.
219  *
220  * \return On success, returns command's assigned unique id.
221  * Otherwise NoUid is returned.
222  */
224  const std::string &strName = "bt");
225 
226  } // namespace addons
227  } // namespace cmd
228 } // namespace rnr
229 
230 #endif // _RNR_CMD_ADD_ONS_H
int printCmdHelp(std::ostream &os, const CmdDef &cmddef, const HelpSect section=HelpSectAll)
Print help for a command convenience function.
User available command description structure.
Definition: CmdCore.h:85
Compiled command definition class.
Definition: CmdDef.h:88
Command line interface class interface.
HelpSect
Command help section identifiers.
Definition: CmdAddOns.h:95
command name help section
Definition: CmdAddOns.h:98
Command line command definition class interface.
int addBtEnableCommand(CommandLine &cli, const std::string &strName="bt")
Add the core &#39;bt&#39; command to the command-line interface.
int addHelpCommand(CommandLine &cli, const std::string &strName="help")
Add the core &#39;help&#39; command to the command-line interface.
command brief description help section
Definition: CmdAddOns.h:99
command usage (synopsis) help section
Definition: CmdAddOns.h:100
RoadNarrows Robotics.
Definition: Camera.h:74
all commond help sections
Definition: CmdAddOns.h:97
CommandLine class.
Definition: CommandLine.h:444
int addQuitCommand(CommandLine &cli, const std::string &strName="quit")
Add the core &#39;quit&#39; command to the command-line interface.