{"id":31548114,"url":"https://github.com/s-r-e-e-r-a-j/clargs","last_synced_at":"2025-10-04T16:04:25.886Z","repository":{"id":314739523,"uuid":"1056576802","full_name":"s-r-e-e-r-a-j/Clargs","owner":"s-r-e-e-r-a-j","description":"Clargs is a lightweight, flexible, and powerful C programming language header-only library for parsing command-line arguments.","archived":false,"fork":false,"pushed_at":"2025-09-30T17:27:42.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-30T19:13:49.788Z","etag":null,"topics":["c-argument-parsing-library","clanguage","clanguagelibrary","cprogramming","cprogramming-language","headerfile"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s-r-e-e-r-a-j.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-14T11:41:34.000Z","updated_at":"2025-09-30T17:27:45.000Z","dependencies_parsed_at":"2025-09-14T14:29:11.184Z","dependency_job_id":"d03825b1-0e1e-456c-96cf-35de7c418f67","html_url":"https://github.com/s-r-e-e-r-a-j/Clargs","commit_stats":null,"previous_names":["s-r-e-e-r-a-j/clargs"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/s-r-e-e-r-a-j/Clargs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-r-e-e-r-a-j%2FClargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-r-e-e-r-a-j%2FClargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-r-e-e-r-a-j%2FClargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-r-e-e-r-a-j%2FClargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s-r-e-e-r-a-j","download_url":"https://codeload.github.com/s-r-e-e-r-a-j/Clargs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-r-e-e-r-a-j%2FClargs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278335469,"owners_count":25970131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-argument-parsing-library","clanguage","clanguagelibrary","cprogramming","cprogramming-language","headerfile"],"created_at":"2025-10-04T16:03:44.419Z","updated_at":"2025-10-04T16:04:25.860Z","avatar_url":"https://github.com/s-r-e-e-r-a-j.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Clargs – Command-Line Argument Parsing header-only library for C\n\nClargs is a lightweight, flexible, and powerful C programming language header-only library for parsing command-line arguments. It supports a wide variety of argument types, including flags, strings, characters, integers, floats, doubles, and more. It is designed to make building command-line tools in C easier, safer, and more robust.\n\n## Features\n\n- **Supports multiple argument types**\n  - Boolean flags (`-f`, `--flag`)\n  - Strings (`char *`)\n  - Character (`char`)\n  - Short, Int, Long, Long Long (`short`, `int`, `long`, `long long`)\n  - Unsigned variants (`unsigned char`, `unsigned short`, `unsigned int`, `unsigned long`, `unsigned long long`)\n  - Size (`size_t`)\n  - Floating-point (`float`, `double`)\n  - Positional arguments\n\n- **Default values** for all argument types\n- **Required and optional arguments** support\n- **Automatic help message generation** (`-h` / `--help`)\n- **Short and long options** (`-x` and `--example`)\n- **Easy retrieval** of parsed values through getter functions\n- **Lightweight and portable** — no external dependencies\n- **Dynamic argument array growth** for flexible usage\n\n## Header File Placement\n\n- **Recommended**: Place `clargs.h` in the **same directory** as your `.c` source file.\n```c\n#include \"clargs.h\"\n```\n\n- This works on **Linux, Windows, and macOS** without any extra setup.\n\n- For larger projects, you can place it in a dedicated `include/` folder and adjust the include path, but for most users, keeping it in the same directory is **easiest and safest**.\n\n## Creating Argument Parser\n\n```c\nClargs *cl_create(const char *prog, const char *desc);\n```\n- **prog**: Program name (e.g., `\"myprogram\"`).\n- **desc**: Description of the program (`shown in help`).\n\n- Returns a pointer to a `Clargs` parser object.\n\n**Example:**\n```c\nClargs *args = cl_create(\"myprog\", \"This is a sample parser\");\n```\n## Adding Arguments\n\n1. **Flag (boolean)**\n```c\nint cl_add_flag(Clargs *p, char short_name, const char *long_name, const char *help);\n```\n\n- **short_name**: `-f`\n\n- **long_name**: `--flag`\n\n- **help**: Description\n\n- Required: Flags are **optional** (presence = 1, absence = 0)\n\n**Example:**\n```c\ncl_add_flag(args, 'v', \"verbose\", \"Enable verbose output\");\n// Use: ./myprog -v\n```\n\n---\n\n2. **String**\n```c\nint cl_add_string(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, const char *def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n **Example:**\n```c\ncl_add_string(args, 'n', \"name\", \"NAME\", \"User name\", 1, NULL); // Required\ncl_add_string(args, 'c', \"city\", \"CITY\", \"User city\", 0, \"Unknown\"); // Optional\n```\n\n---\n\n3. **Char**\n```c\nint cl_add_char(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, char def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_char(args, 'g', \"gender\", \"GENDER\", \"User gender\", 0, 'U'); // Optional\n```\n\n---\n\n4. **Short**\n```c\nint cl_add_short(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, short def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_short(args, 's', \"score\", \"SCORE\", \"User score\", 0, 10);\n```\n\n---\n\n5. **Int**\n```c\nint cl_add_int(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, int def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_int(args, 'i', \"iterations\", \"N\", \"Number of iterations\", 0, 100);\ncl_add_int(args, 0, \"count\", \"COUNT\", \"Count of items\", 1, 0); // Required\n```\n\n---\n\n6. **Long**\n```c\nint cl_add_long(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, long def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_long(args, 0, \"timeout\", \"TIMEOUT\", \"Timeout in ms\", 0, 5000);\n```\n\n---\n\n7. **Long long**\n```c\nint cl_add_llong(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, long long def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_llong(args, 0, \"bigval\", \"BIGVAL\", \"Large integer value\", 0, 1234567890123LL);\n```\n\n---\n\n8. **Size_t**\n```c\nint cl_add_size(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, size_t def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_size(args, 0, \"bufsize\", \"SIZE\", \"Buffer size\", 0, 1024);\n```\n\n---\n\n9. **Float**\n```c\nint cl_add_float(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, float def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_float(args, 0, \"ratio\", \"RATIO\", \"Scaling ratio\", 0, 1.5f);\n```\n\n---\n\n10. **Double**\n```c\nint cl_add_double(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, double def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n\n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_double(args, 0, \"threshold\", \"THRESH\", \"Double value\", 0, 0.123);\n```\n\n---\n\n11. **Unsigned Char**\n```c\nint cl_add_uchar(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, unsigned char def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed.  \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_uchar(args, 'u', \"usergender\", \"UCHAR\", \"User gender code\", 0, 1);\n```\n\n ---\n\n12. **Unsigned Short**\n```c\nint cl_add_ushort(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, unsigned short def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed. \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_ushort(args, 0, \"portnum\", \"PORT\", \"Port number\", 0, 8080);\n```\n\n---\n\n13. **Unsigned Int**\n```c\nint cl_add_uint(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, unsigned int def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed. \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_uint(args, 's', \"buffersize\", \"SIZE\", \"Buffer size\", 0, 1024);\n```\n\n---\n\n14. **Unsigned Long**\n```c\nint cl_add_ulong(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, unsigned long def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed. \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_ulong(args, 0, \"maxbytes\", \"MAXBYTES\", \"Maximum bytes allowed\", 0, 500000UL);\n```\n\n---\n\n15. **Unsigned Long Long**\n```c\nint cl_add_ullong(Clargs *p, char short_name, const char *long_name, const char *meta, const char *help, int req, unsigned long long def);\n```\n\n- **`short_name`**: Corresponds to a single-dash option like `-n`. Pass `0` if not needed.\n   \n- **`long_name`**: Corresponds to a double-dash option like `--number`. Pass `0` if not needed.\n  \n- **meta** is the place-holder name shown in usage (e.g., `--name NAME`).\n\n- **`help`**: The help message describing the option. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional, `def`(`default`) is used if missing\n\n- **`def`**: The default value for the argument.  \n  - For strings: pass `NULL` if no default is needed.  \n  - For numeric types: pass `0` if no default is needed. \n  - For `char`: pass `'\\0'` if no default is needed.\n\n**Example:**\n```c\ncl_add_ullong(args, 0, \"hugeval\", \"HUGEVAL\", \"Very large integer value\", 0, 123456789012345ULL);\n```\n\n---\n\n16. **Positional Arguments**\n```c\nint cl_add_pos(Clargs *p, const char *name, const char *help, int req);\n```\n\n- **`name`**: The name of the positional argument. This will be used to identify it.\n  \n- **`help`**: The help message describing the positional argument. Pass `NULL` if not needed.\n\n- **req(required) = 1** → User must provide\n\n- **req(required) = 0** → Optional\n\n**Example:**\n```c\ncl_add_pos(args, \"input\", \"Input filename\", 1);  // Required positional argument\ncl_add_pos(args, \"output\", \"Output filename\", 0); // Optional positional\n```\n\n---\n\n## Parsing Arguments\n```c\nint cl_parse(Clargs *p, int argc, char **argv);\n```\n\n- Parses `argc/argv`.\n\n- Returns `0` on success, `-1` on error.\n\n- Automatically checks required arguments.\n\n**Example:**\n```c\nif (cl_parse(args, argc, argv) != 0) {\n    fprintf(stderr, \"Error parsing arguments\\n\");\n    return 1;\n}\n```\n\n---\n\n## Accessing Argument Values\n\nAll getters except `cl_get_flag` and `cl_get_string` optionally provide a pointer to `ok` to check if value exists.\n```c\nint ok;\nconst char *name = cl_get_string(args, \"name\");\nint iter = cl_get_int(args, \"iterations\", \u0026ok);\nif(ok) printf(\"Iterations = %d\\n\", iter);\n```\n\n| Function          | Returns               | Example                                  |\n|-------------------|-----------------------|------------------------------------------|\n| cl_get_flag       | int (0/1)             | cl_get_flag(args, \"verbose\");            |\n| cl_get_string     | const char *          | cl_get_string(args, \"name\");             |\n| cl_get_char       | char                  | cl_get_char(args, \"gender\", \u0026ok);        |\n| cl_get_short      | short                 | cl_get_short(args, \"score\", \u0026ok);        |\n| cl_get_int        | int                   | cl_get_int(args, \"count\", \u0026ok);          |\n| cl_get_long       | long                  | cl_get_long(args, \"timeout\", \u0026ok);       |\n| cl_get_llong      | long long             | cl_get_llong(args, \"bigval\", \u0026ok);       |\n| cl_get_uchar      | unsigned char         | cl_get_uchar(args, \"level\", \u0026ok);        |\n| cl_get_ushort     | unsigned short        | cl_get_ushort(args, \"port\", \u0026ok);        |\n| cl_get_uint       | unsigned int          | cl_get_uint(args, \"size\", \u0026ok);          |\n| cl_get_ulong      | unsigned long         | cl_get_ulong(args, \"maxval\", \u0026ok);       |\n| cl_get_ullong     | unsigned long long    | cl_get_ullong(args, \"hugeval\", \u0026ok);     |\n| cl_get_size       | size_t                | cl_get_size(args, \"bufsize\", \u0026ok);       |\n| cl_get_float      | float                 | cl_get_float(args, \"ratio\", \u0026ok);        |\n| cl_get_double     | double                | cl_get_double(args, \"pi\", \u0026ok);          |\n\n\n---\n\n## Help Message\n```c\nvoid cl_help(Clargs *p);\n```\n\n- Automatically prints usage and description.\n\n- Includes all arguments, defaults, and required info.\n\n**Example:**\n```c\ncl_help(args);\n```\n\n---\n\n## Freeing Resources\n```c\nvoid cl_free(Clargs *p);\n```\n\n- Frees memory used by parser.\n\n**Example:**\n```c\ncl_free(args);\n```\n\n## Example program\n```c\n/*\n  Example program using clargs.h\n  --------------------------------\n  - Shows how to add every argument type\n  - Shows how to get values back\n  - Uses \u0026ok to check if argument is registered\n  - Remember: use 1 for required, 0 for optional\n  - You can pass 0 for short_name or long_name if you don't need them\n*/\n\n#include \u003cstdio.h\u003e\n#include \"clargs.h\"\n\nint main(int argc, char **argv) {\n    int ok;\n\n    // Create parser\n    Clargs *args = cl_create(\"example\", \"Demo of all clargs functions\");\n\n    // Add different argument types\n    cl_add_flag(args, 'v', \"verbose\", \"Enable verbose mode\");                 // flag\n    cl_add_string(args, 'n', \"name\", \"NAME\", \"User name\", 0, \"guest\");        // string\n    cl_add_char(args, 0, \"gender\", \"GENDER\", \"Gender (M/F)\", 0, 'U');         // char\n    cl_add_short(args, 's', \"score\", \"SCORE\", \"Short number\", 0, 10);         // short\n    cl_add_int(args, 'p', \"port\", \"PORT\", \"Port number\", 0, 8080);            // int\n    cl_add_long(args, 0, \"timeout\", \"TIMEOUT\", \"Timeout in ms\", 0, 5000L);    // long\n    cl_add_llong(args, 0, \"bigval\", \"BIGVAL\", \"Big 64-bit number\", 0, 123456789LL); // long long\n    cl_add_uchar(args, 0, \"ubyte\", \"UBYTE\", \"Unsigned char\", 0, 255);         // unsigned char\n    cl_add_ushort(args, 0, \"u16\", \"U16\", \"Unsigned short\", 0, 65000);         // unsigned short\n    cl_add_uint(args, 0, \"u32\", \"U32\", \"Unsigned int\", 0, 123456789u);        // unsigned int\n    cl_add_ulong(args, 0, \"ulong\", \"ULONG\", \"Unsigned long\", 0, 1234567890UL);// unsigned long\n    cl_add_ullong(args, 0, \"ull\", \"ULLONG\", \"Unsigned long long\", 0, 1234567890123ULL); // unsigned long long\n    cl_add_size(args, 0, \"bufsize\", \"SIZE\", \"Buffer size\", 0, 4096);          // size_t\n    cl_add_float(args, 0, \"ratio\", \"RATIO\", \"Float value\", 0, 0.75f);         // float\n    cl_add_double(args, 0, \"threshold\", \"THRESH\", \"Double value\", 0, 0.123);  // double\n    cl_add_pos(args, \"input\", \"Input file\", 1);                               // positional (required)\n\n    // Parse command-line\n    if (cl_parse(args, argc, argv) != 0) {\n        cl_free(args);\n        return 1;\n    }\n\n    // Get values back\n    printf(\"verbose   : %d\\n\", cl_get_flag(args, \"verbose\"));\n    printf(\"name      : %s\\n\", cl_get_string(args, \"name\"));\n\n    char gender = cl_get_char(args, \"gender\", \u0026ok);\n    if (ok) printf(\"gender    : %c\\n\", gender);\n\n    short score = cl_get_short(args, \"score\", \u0026ok);\n    if (ok) printf(\"score     : %d\\n\", score);\n\n    int port = cl_get_int(args, \"port\", \u0026ok);\n    if (ok) printf(\"port      : %d\\n\", port);\n\n    long timeout = cl_get_long(args, \"timeout\", \u0026ok);\n    if (ok) printf(\"timeout   : %ld\\n\", timeout);\n\n    long long bigval = cl_get_llong(args, \"bigval\", \u0026ok);\n    if (ok) printf(\"bigval    : %lld\\n\", bigval);\n\n    unsigned char ubyte = cl_get_uchar(args, \"ubyte\", \u0026ok);\n    if (ok) printf(\"ubyte     : %u\\n\", ubyte);\n\n    unsigned short u16 = cl_get_ushort(args, \"u16\", \u0026ok);\n    if (ok) printf(\"u16       : %u\\n\", u16);\n\n    unsigned int u32 = cl_get_uint(args, \"u32\", \u0026ok);\n    if (ok) printf(\"u32       : %u\\n\", u32);\n\n    unsigned long ul = cl_get_ulong(args, \"ulong\", \u0026ok);\n    if (ok) printf(\"ulong     : %lu\\n\", ul);\n\n    unsigned long long ull = cl_get_ullong(args, \"ull\", \u0026ok);\n    if (ok) printf(\"ull       : %llu\\n\", ull);\n\n    size_t bufsize = cl_get_size(args, \"bufsize\", \u0026ok);\n    if (ok) printf(\"bufsize   : %zu\\n\", bufsize);\n\n    float ratio = cl_get_float(args, \"ratio\", \u0026ok);\n    if (ok) printf(\"ratio     : %f\\n\", ratio);\n\n    double thresh = cl_get_double(args, \"threshold\", \u0026ok);\n    if (ok) printf(\"threshold : %f\\n\", thresh);\n\n    printf(\"input     : %s\\n\", cl_get_string(args, \"input\"));\n\n    // Free parser\n    cl_free(args);\n    return 0;\n}\n\n```\n\n## License\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-r-e-e-r-a-j%2Fclargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs-r-e-e-r-a-j%2Fclargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-r-e-e-r-a-j%2Fclargs/lists"}