{"id":42165726,"url":"https://github.com/pedramcode/cargs","last_synced_at":"2026-01-26T21:01:01.583Z","repository":{"id":127627259,"uuid":"596002812","full_name":"pedramcode/cargs","owner":"pedramcode","description":"A C/C++ argument parser library","archived":false,"fork":false,"pushed_at":"2023-02-15T15:57:16.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-08T13:07:07.421Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pedramcode.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":"2023-02-01T09:01:42.000Z","updated_at":"2023-02-02T15:40:33.000Z","dependencies_parsed_at":"2026-01-26T21:00:15.815Z","dependency_job_id":null,"html_url":"https://github.com/pedramcode/cargs","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"purl":"pkg:github/pedramcode/cargs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedramcode%2Fcargs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedramcode%2Fcargs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedramcode%2Fcargs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedramcode%2Fcargs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pedramcode","download_url":"https://codeload.github.com/pedramcode/cargs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedramcode%2Fcargs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28788064,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-26T21:00:28.871Z","updated_at":"2026-01-26T21:01:01.562Z","avatar_url":"https://github.com/pedramcode.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CArgs\nA C/C++ argument parser library\n\n## Requirements\n* GCC\n* Cmake\n* make\n\n## Installation\n1. Inside project, make a directory named 'build': `mkdir build`\n2. Change directory to 'build' folder: `cd build`\n3. Execute cmake command: `cmake ..`\n4. Make project: `make`\n5. Install library: `make install`\n\n## Usage\nCreate an array of `CargsMap_t` structure and define the arguments map:\n\n````c\nCargsMap_t *map = {\n    {\"first-name\", 'f', true, \"User first name\"},\n    {\"last-name\", 'l', true, \"User last name\"},\n    {\"email\", 'e', false, \"Email address\"}\n};\n````\n\nThe `CargsMap_t` structure fields are:\n* `w_key`: An string argument key and starts with two dashes (`--`) as input (Example: `--first-name`)\n* `c_key`: A character argument key and starts with a dash (`-`) as input (Example: `-f`)\n* `required`: If this flag be true, then it should include as input, Otherwise input is invalid\n* `desc`: Description of argument that shows with `help` argument\n* `value`: If value was provided in arguments input, the value of key will get copy in this field after parsing\n\nThen declare a variable with type of `size_t` that contains length of map fields.\n\n```c\nsize_t map_size = 3;\n```\n\nThen parse the arguments by passing **map array**, **map array length**, `int argc`, `char **argv` to `cargs_parse` function like this:\n\n```c\ncargs_parse(map, map_size, argc, argv);\n```\n\nParsing will read fields from input and sets value of each map field from it.\n\nYou can validate the input after parsing by calling this function:\n\n```c\nbool is_valid = cargs_validate(map, map_size, true);\n```\n\n* First argument is array of map\n* Second argument is length of map\n* Third argument is boolean that determines after detecting an invalid argument exit from process or not \n\nReturn value of this function is a boolean.\n\nYou can call `cargs_get` to get value of an argument:\n\n```c\nchar* first_name = cargs_get(map, map_size, \"first-name\");\n```\n\n* First argument is array of map\n* Second argument is length of map\n* Third argument is `w_key` value of a map field. Then returns value of argument if exists. Otherwise returns `NULL` \n\nYou can print help message by calling `cargs_help` function:\n\n```c\ncargs_help(map, map_size);\n```\n\n* First argument is array of map\n* Second argument is length of map\n\nAlso, this message can display using `help` special argument:\n\n```shell\n./your_exe help\n```\n\n### Example\n\n```c\n#include \u003ccargs.h\u003e\n#include \u003cstdio.h\u003e\n\nint main(int argc, char **argv){\n    CargsMap_t *map = {\n        {\"first-name\", 'f', true, \"User first name\"},\n        {\"last-name\", 'l', true, \"User last name\"},\n        {\"email\", 'e', false, \"Email address\"}\n    };\n   size_t map_size = 3;\n   cargs_parse(map, map_size, argc, argv);\n   \n   bool is_valid = cargs_validate(map, map_size, true);\n   char* first_name = cargs_get(map, map_size, \"first-name\");\n   char* last_name = cargs_get(map, map_size, \"last-name\");\n   \n   printf(\"User fullname: %s %s\\n\", first_name, last_name);\n   return 0;\n}\n```\n\nExecution:\n\n```shell\n./your_exe --first-name Pedram --last-name Dehghanpour\n```\n\nor\n\n```shell\n./your_exe -f Pedram -l Dehghanpour\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedramcode%2Fcargs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedramcode%2Fcargs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedramcode%2Fcargs/lists"}