https://github.com/rxn7/redflag
c99 library for CLI flag/option management
https://github.com/rxn7/redflag
c99 cli flags library
Last synced: 12 months ago
JSON representation
c99 library for CLI flag/option management
- Host: GitHub
- URL: https://github.com/rxn7/redflag
- Owner: rxn7
- Created: 2023-07-24T03:32:50.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-14T09:22:01.000Z (over 2 years ago)
- Last Synced: 2025-03-31T03:47:06.685Z (over 1 year ago)
- Topics: c99, cli, flags, library
- Language: C
- Homepage: https://maciejniziolek.xyz/#/project/redflag
- Size: 43.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RedFlag
stb-style **c99** library for handling flags in CLI applications.

# Example
See ```example.c```
# Usage
- Include the library in your header files
```C++
#include "redflag.h"
```
- In **only one** source file include the library but declare **REDFLAG_IMPLEMENTATION** first.
```C++
#define REDFLAG_IMPLEMENTATION
#include "redflag.h"
```
- Create and init a context instance
```C++
rf_context_t ctx;
rf_init_context(&ctx);
```
- Add options/flags
```C++
rf_flag_bool(ctx*, name, desc, default_value);
rf_flag_int(ctx*, name, desc, default_value);
rf_flag_float(ctx*, name, desc, default_value);
rf_flag_str(ctx*, name, desc, default_value);
// All of these functions return a rf_flag_t pointer that is owned by the context
```
- After you have declared all your options/flags you can parse them
```C++
rf_parse_flags(&ctx, argc, argv);
```
- After you have parsed the options/flags you can check their values
```C++
rf_flag_t* flag = rf_flag_str(&ctx, "test", "this is a test value", "default value");
rf_parse_flags(&ctx, argc, argv);
const char *value = flag->value.as_str;
printf("Value: %s\n", value);
```
- Remember to free the allocated memory
```C++
rf_free_context(&ctx);
```