proxygen
NestedCommandLineAppExample.cpp File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 166 of file NestedCommandLineAppExample.cpp.

References folly::NestedCommandLineApp::addCommand(), folly::NestedCommandLineApp::addGFlags(), and folly::NestedCommandLineApp::run().

166  {
167  // Initialize a NestedCommandLineApp object.
168  //
169  // The first argument is the program name -- an empty string will cause the
170  // program name to be deduced from the executable name, which is usually
171  // fine. The second argument is a version string.
172  //
173  // You may also add an "initialization function" that is always called
174  // for every valid command before the command is executed.
175  folly::NestedCommandLineApp app("", "0.1");
176 
177  // Add any GFlags-defined flags. These are global flags, and so they should
178  // be valid for any command.
179  app.addGFlags();
180 
181  // Add any commands. For our example, we'll implement simplified versions
182  // of "cat" and "echo". Note that addCommand() returns a reference to a
183  // boost::program_options object that you may use to add command-specific
184  // options.
185  // clang-format off
186  app.addCommand(
187  // command name
188  "cat",
189 
190  // argument description
191  "[file...]",
192 
193  // short help string
194  "Concatenate files and print them on standard output",
195 
196  // Long help string
197  "Concatenate files and print them on standard output.",
198 
199  // Function to execute
200  runCat)
201  .add_options()
202  ("number,n", po::bool_switch(), "number all output lines");
203  // clang-format on
204 
205  // clang-format off
206  app.addCommand(
207  "echo",
208  "[string...]",
209  "Display a line of text",
210  "Display a line of text.",
211  runEcho)
212  .add_options()
213  (",n", po::bool_switch(), "do not output the trailing newline");
214  // clang-format on
215 
216  // You may also add command aliases -- that is, multiple command names
217  // that do the same thing; see addAlias().
218 
219  // app.run returns an appropriate error code
220  return app.run(argc, argv);
221 }
char ** argv