This commit is contained in:
46
README.md
Normal file
46
README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# CgeArgs - CLI argument parsing
|
||||
|
||||
TODO
|
||||
|
||||
## Usage Example
|
||||
|
||||
```c
|
||||
#include "CgeArgs.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int boolOption = 0, intOption = 0;
|
||||
const char *strOption = "default";
|
||||
float floatOption = 0;
|
||||
double doubleOption = 0;
|
||||
int i;
|
||||
|
||||
CgeArgs args[] = {
|
||||
{'a', "a", CGE_ARGS_BOOL, &boolOption},
|
||||
{'b', "b", CGE_ARGS_INT, &intOption},
|
||||
{'c', "c", CGE_ARGS_STRING, &strOption},
|
||||
{'d', "d", CGE_ARGS_FLOAT, &floatOption},
|
||||
{'e', "e", CGE_ARGS_DOUBLE, &doubleOption},
|
||||
};
|
||||
|
||||
i = CgeArgsParse(args, sizeof(args) / sizeof(CgeArgs), argc, argv);
|
||||
if (i != -1) {
|
||||
printf("bool: %d\n", boolOption);
|
||||
printf("int: %d\n", intOption);
|
||||
printf("str: %s\n", strOption);
|
||||
printf("float: %f\n", floatOption);
|
||||
printf("double: %lf\n", doubleOption);
|
||||
|
||||
for (; i < argc; i++) {
|
||||
printf("free arg: %s\n", argv[i]);
|
||||
}
|
||||
} else {
|
||||
printf("unknown arg\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
0BSD - a permissive license with no attribution required.
|
||||
Reference in New Issue
Block a user