Browse Source

README

master
parent
commit
f4c6ef8cb2
  1. 30
      README.md
  2. 27
      testing/test.c

30
README.md

@ -2,10 +2,38 @@
## Installation
1. `git clone https://unbewohnte.su:3000/Unbewohnte/flagok.git`
2. Either `make static`|`make` to make a static|shared library (if you have make and other *NIX utilities) or simply put header file into your project and compile it your own way
## Usage
### Example
Each flag has its `name`, `value`, `description` and
- `flag_bool` (bool)
- `flag_int` (long long)
- `flag_uint` (unsigned long long)
- `flag_double` (long double)
- `flag_string` (char*)
are available to be called
Example:
```
long long int_value = 1;
char* string_value = "hello";
bool bool_value = false;
flag_int(&int_value, "-intval", "set int");
flag_str(&string_value, "-stringval", "set string");
flag_bool(&bool_value, "-boolval", "set true or false");
flag_parse(argc, argv);
```
`-help` flag is set automatically and when presented, prints all registered flags' information to stdout
Right now the parsing process is not strict and does not output any errors. When for example the argument to integer flag was not provided - the parse function will simply move on onto the next argument and leave the current value untouched.
## License
LGPLv3

27
testing/test.c

@ -1,20 +1,3 @@
/*
FLAGOK - C/C++ command line flags library
Copyright (C) 2022 Kasyanov Nikolay Alexeyevich (Unbewohnte)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../src/flagok.h"
int main(int argc, char** argv) {
@ -22,19 +5,19 @@ int main(int argc, char** argv) {
char* input = "hello";
bool to_do_or_not = false;
flag_int(&iteration, "-iteration", "set iterations");
flag_int(&iteration, "-iter", "set iterations");
flag_str(&input, "-input", "set input");
flag_bool(&to_do_or_not, "-to_do_or_not", "set true or false");
flag_bool(&to_do_or_not, "-to_do", "set true or false");
printf("Flags before parsing\n");
printf("iter %lld\n", iteration);
printf("input %s\n", input);
printf("todo %d\n", to_do_or_not);
printf("to_do %d\n", to_do_or_not);
flag_parse(argc, argv);
printf("Flags after parsing\n");
printf("\nFlags after parsing\n");
printf("iter %lld\n", iteration);
printf("input %s\n", input);
printf("todo %d\n", to_do_or_not);
printf("to_do %d\n", to_do_or_not);
}
Loading…
Cancel
Save