https://github.com/ellectroid/clinput-arg-parser
https://github.com/ellectroid/clinput-arg-parser
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ellectroid/clinput-arg-parser
- Owner: ellectroid
- License: unlicense
- Created: 2024-05-21T07:37:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-04T09:35:45.000Z (over 1 year ago)
- Last Synced: 2025-07-27T21:00:59.214Z (7 months ago)
- Language: C++
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is a command line argument parser.
This is a demo project.
Example:
Console input:
>app.exe action=makediskimage inputpath=\\.\PhysicalDrive0 verbosity-level=2
Clinput output (configurable):
RAM contains
>struct clinput_output{
> char input_file_path[32];
> int action_code;
> int verbosity_level;
>}
(can freely move members of struct around in the definition, resize the array and it won't break anything!!!)
Key points:
-Simplicity of use: easy to configure for your app's argument names and their parse types (see "impl" files)
-Output data structure from the console input arguments is fully user-defined. No limits.
-Modularity: can hook up another parser function for any type, user-defined types
-Internal modularity: data is processed in multiple stages, so things can be easily adjusted, improved
-Error checking: functions return error codes
-Handles only the arguments provided, if there is an unknown argument, throws an error, tells what argument wasn't recognized
-It doesn't care about specific output types. You can easily specify your own type with any memory layout and your own parser behavior (which is the point)
-Each parser is just a single function with a fixed signature, the parser is provided with input data and output type information. The parser function can do anything.
-A couple basic parsers included (for output types argument value charstr to charstr, to int, to float, unsigned long long, signed long long)
-An example that takes advantage of modularity and customizability by using a default integer parser, as well as user-defined types, and a custom argument value string to integer parser
How it works:
When you pass arguments, they're a bunch of strings "app.exe" "argstring1" "argstring2" "argstring3".
Stage 1 calls "raw argument to argname=argval". It finds "=" and breaks the argument apart into separate argument name strings and value strings.
Stage 2 binds parser functions to types (a vtable).
Stage 3 binds user-defined argument names to types, output memory structure
Stage 4 parser takes output of stage 1 (argname=argval), goes through every argument, looks up its type and invokes the corresponding parser