|
2 | 2 | =======
|
3 | 3 |
|
4 | 4 | Object Oriented Command Line Interface Library of C++
|
| 5 | + |
| 6 | +Introduce |
| 7 | +-------- |
| 8 | +This is |
| 9 | + |
| 10 | +Usage |
| 11 | +-------- |
| 12 | +First, define a Request struct, include all possible parameters |
| 13 | +Second, define a Context class, include the |
| 14 | +Thirdly, define the class and actions of the cli |
| 15 | +Finally, call cli_invoke to parse request and execute actions. |
| 16 | + |
| 17 | +Here are some example: |
| 18 | + |
| 19 | +### Simple |
| 20 | + #include <obj-cli.h> |
| 21 | + struct Request{ |
| 22 | + CLI_DECLARE(param1); |
| 23 | + CLI_DECLARE(param2); |
| 24 | + } |
| 25 | + struct Context{ |
| 26 | + const char *password; |
| 27 | + } |
| 28 | + int func_dummy1(Request &, Context *){ |
| 29 | + return 0; |
| 30 | + } |
| 31 | + int func_dummy1(Request &, Context *){ |
| 32 | + return 0; |
| 33 | + } |
| 34 | + CliObject<Request,Context> meta[] = { |
| 35 | + { |
| 36 | + "class1", { |
| 37 | + { |
| 38 | + "action1", |
| 39 | + func_dummy, |
| 40 | + { |
| 41 | + } |
| 42 | + }, |
| 43 | + "action2", |
| 44 | + func_dummy2, |
| 45 | + { |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + }, { |
| 50 | + "class2",{ |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
| 54 | + // ./a.out class1 action1 --param1=a --param2=b |
| 55 | + // ./a.out class1 action2 --param2=a |
| 56 | + int main(int argc, const char *argv[]) { |
| 57 | + return cli_invoke<Request, Context>(argc, argv, meta, 3); |
| 58 | + } |
| 59 | +### Advanced |
| 60 | + int main(int argc, const char* argv[]) { |
| 61 | + Request request; |
| 62 | + Context context; |
| 63 | + InvokeContext<Request, Context> env(argv[0], g_meta, meta_num, g_opt, opt_num); |
| 64 | + int ret = cli_parse(argc, argv, request, env); |
| 65 | + if(0 != ret){ |
| 66 | + return ret; |
| 67 | + } |
| 68 | + if(0 != strcmp(request.password, "secret")){ |
| 69 | + return -1; |
| 70 | + } |
| 71 | + context.password = "holy pot"; |
| 72 | + return cli_invoke(request, context, env); |
| 73 | + } |
| 74 | + |
| 75 | +About |
| 76 | +-------- |
| 77 | +For more information, please refer to the code |
| 78 | +For more and more information, please contact me via email which hides in codes. |
0 commit comments