add how-to-use for command data structure

This commit is contained in:
tangxifan 2020-01-20 22:53:11 -07:00
parent 7a5b36fe52
commit b53897b838
1 changed files with 33 additions and 0 deletions

View File

@ -42,6 +42,39 @@ enum e_option_value_type {
* This data structure should NOT contain any parsing results!
* It should be a read-only once created!
*
* An exampe of how to use
* -----------------------
* // Create a new command with a name of 'read_file'
* // This command can be called as
* // read_file --file <file_name>
* // read_file -f <file_name>
* // read_file --help
* // read_file -h
* Command cmd("read_file");
*
* // Add a mandatory option 'file' to the command
* CommandOptionId opt_file = cmd.add_option("file", true, "Input file path");
* // Add a short name 'f' for 'file' option
* cmd.set_option_short_name(opt_file, "f");
* // The option require a string value which is the file path
* cmd.set_option_require_value(opt_file, OPT_STRING);
*
* // Add an non-mandatory option 'help' to the command
* // which does not require a value
* CommandOptionId opt_help = cmd.add_option("help", false, "Show help desk");
* // Add a short name 'h' for 'help' option
* cmd.set_option_short_name(opt_help, "h");
*
* // Run a command parser and store the results in CommandContext
* CommandContext cmd_context(cmd);
* if (false == parse_command(cmd_opts, cmd, cmd_context)) {
* // Parse failed. Print the help desk
* print_command_options(cmd);
* } else {
* // Parse succeed. Let user to confirm selected options
* print_command_context(cmd, cmd_context);
* }
*
* Note:
* When adding an option name, please do NOT add any dash at the beginning!!!
********************************************************************/