MCPcopy Create free account
hub / github.com/OpenVPN/openvpn3-linux / main

Function main

src/tests/command-parser/cmdparser.cpp:115–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114
115int main(int argc, char **argv)
116{
117 Commands cmds("Command line parser test",
118 "Simple example and test tool for the command line parser");
119
120 SingleCommand::Ptr test1_cmd;
121 test1_cmd.reset(new SingleCommand("test1", "Test command 1", cmd_dump_arg_test));
122 test1_cmd->AddComment(SingleCommand::CommentPlacement::BEFORE_OPTS, "Various option parsing tests for the option parser");
123 test1_cmd->AddOption("set-value", 's', "key", true, "Set a variable");
124 test1_cmd->AddOption("test-func1", "Just testing more options");
125 test1_cmd->AddOption("test-func2", 'f', "string", false, "Just another test");
126 test1_cmd->AddOption("mandatory-arg", "string", true, "Test mandatory option argument", arghelper_mandatory_arg);
127 test1_cmd->AddVersionOption();
128 cmds.RegisterCommand(test1_cmd);
129
130 SingleCommand::Ptr test2_cmd;
131 test2_cmd.reset(new SingleCommand("test2", "Test command two", cmd_multiply));
132 test2_cmd->AddComment(SingleCommand::CommentPlacement::AFTER_OPTS, "These tests and options doesn't really do that much");
133 test2_cmd->AddOption("multiply", 'm', "values", true, "Multiply two numbers", arghelper_random_numbers);
134 test2_cmd->AddOption("bool-test", 'b', "<true|false>", true, "Test of a boolean option", arghelp_boolean);
135 cmds.RegisterCommand(test2_cmd);
136
137 SingleCommand::Ptr test3_cmd;
138 test3_cmd.reset(new SingleCommand("test3", "Test command 3", cmd_dump_arg_test));
139 test3_cmd->AddComment(SingleCommand::CommentPlacement::BEFORE_OPTS, "Yet more testing, a comment before the option");
140 test3_cmd->AddComment(SingleCommand::CommentPlacement::AFTER_OPTS, "And more comments below");
141 test3_cmd->AddComment(SingleCommand::CommentPlacement::AFTER_OPTS, "This one even has two lines of comments");
142 test3_cmd->AddOption("opt-string", 'o', "string-1", false, "Optional strings");
143 cmds.RegisterCommand(test3_cmd);
144
145 try
146 {
147 return cmds.ProcessCommandLine(argc, argv);
148 }
149 catch (CommandException &e)
150 {
151 if (e.gotErrorMessage())
152 {
153 std::cerr << e.getCommand() << ": ** ERROR ** " << e.what() << std::endl;
154 }
155 }
156}

Callers

nothing calls this directly

Calls 9

AddCommentMethod · 0.80
AddVersionOptionMethod · 0.80
RegisterCommandMethod · 0.80
ProcessCommandLineMethod · 0.80
gotErrorMessageMethod · 0.80
getCommandMethod · 0.80
resetMethod · 0.45
AddOptionMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected