default: // hit unknown option if (!__command_unknown_option_bypass()) { usage(); exit(EXIT_FAILURE); } break; } }
return0; }
代码已经上传到gitee中,感兴趣可以去看看,欢迎交流,提提意见。
https://gitee.com/fishmwei/ccmd
在源码中带有一个example, 运行效果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
root@keep-VirtualBox:/media/sf_VM_SHARE/ccmd/example/build# ./ccmd_test --help Usage ./ccmd_test [options] ... Options: --help: prints this help --name: specify student name --address: specify student home address --age: specify student age --fresh: is fresh graduate
root@keep-VirtualBox:/media/sf_VM_SHARE/ccmd/example/build# ./ccmd_test --name xiaoming --address Fuzhou,Fujian --age 18 --fresh get student info: name : xiaoming address: Fuzhou,Fujian age : 18 fresh : true