{"id":32621105,"url":"https://github.com/noxmor/clapx","last_synced_at":"2026-07-04T15:31:59.912Z","repository":{"id":321229621,"uuid":"1084964228","full_name":"Noxmor/clapx","owner":"Noxmor","description":"Command-line argument parser written in C using X macros","archived":false,"fork":false,"pushed_at":"2025-11-10T19:40:41.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-10T20:33:10.403Z","etag":null,"topics":["c","command-line-arguments-parser","command-line-parser","single-header","single-header-lib","single-header-library","x-macros"],"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/Noxmor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-10-28T12:05:11.000Z","updated_at":"2025-11-10T19:40:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"8477a7b3-4b16-4a33-a797-2d6d0ed06b5e","html_url":"https://github.com/Noxmor/clapx","commit_stats":null,"previous_names":["noxmor/clapx"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Noxmor/clapx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noxmor%2Fclapx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noxmor%2Fclapx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noxmor%2Fclapx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noxmor%2Fclapx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Noxmor","download_url":"https://codeload.github.com/Noxmor/clapx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Noxmor%2Fclapx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35127443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"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","command-line-arguments-parser","command-line-parser","single-header","single-header-lib","single-header-library","x-macros"],"created_at":"2025-10-30T19:00:29.738Z","updated_at":"2026-07-04T15:31:59.902Z","avatar_url":"https://github.com/Noxmor.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clapx\nA command-line argument parser single-header library written in C using [X macros](https://en.wikipedia.org/wiki/X_macro).\n\n***\n\n## Installation\n1. Start by cloning the repository with `git clone https://github.com/Noxmor/clapx`.\n2. Run `make install`.\n3. Done! You can now include the library by typing `#include \u003cclapx/clapx.h\u003e`.\n\u003e [!NOTE]\n\u003e Alternatively, you can also just copy/clone the library locally and include it directly.\n\n***\n\n## How to use\nIn order to use `clapx`, you will want to first define the `CLAPX_FLAGS` and `CLAPX_SUBCOMMANDS` macros to fit the specification of your application.\n\n\u003e [!IMPORTANT]\n\u003e The macros `CLAPX_FLAGS` and `CLAPX_SUBCOMMANDS` must be defined **before** including `clapx` with implementation details.\n\u003e \n\u003e Define `CLAPX_IMPLEMENTATION` before including `clapx` to include the implementation details.\n\n### Global flags\nIn order to define global flags, you will need to define the `CLAPX_FLAGS` macro. Each flag will then be defined via one of the `CLAPX_\u003ctype\u003e_FLAG` macros, like this:\n```c\nvoid help_callback(void);\n\n#define CLAPX_FLAGS \\\n    CLAPX_BOOL_FLAG(help, \"help\", 'h', \"Prints this help message.\", help_callback) \\\n    CLAPX_STRING_FLAG(foo, \"foo\", CLAPX_NO_SHORT, CLAPX_NO_DESC, CLAPX_NO_CALLBACK, \"my-custom-default-string\") \\\n    CLAPX_CHAR_FLAG(bar, CLAPX_ONLY_SHORT('b'), CLAPX_NO_DESC, CLAPX_NO_CALLBACK, 'b')\n```\n\n#### List of macros for defining global flags\n- `CLAPX_BOOL_FLAG(label, long_name, short_name, desc, callback)`\n- `CLAPX_U8_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_U16_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_U32_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_U64_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_I8_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_I16_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_I32_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_I64_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_CHAR_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_STRING_FLAG(label, type, long_name, short_name, desc, callback, default_value)`\n- `CLAPX_CUSTOM_FLAG(label, type, long_name, short_name, desc, callback, parser)`\n\nwhere...\n- `label` is a unique and valid C identifier.\n- `type` is either `CLAPX_FLAG_TYPE_OPT_ARG` or `CLAPX_FLAG_TYPE_REQ_ARG`.\n- `long_name` is a string literal or `CLAPX_NO_LONG`.\n- `short_name` is an alphanumeric character or `CLAPX_NO_SHORT`.\n- `desc` is either a string literal or `CLAPX_NO_DESC`.\n- `callback` is a function pointer of type `clapx_flag_callback_t` or `CLAPX_NO_CALLBACK`. If set, this callback is triggered immediately after the flag is parsed.\n- `parser` is a function pointer of type `clapx_custom_parser_callback_t`.\n\n\u003e [!NOTE]\n\u003e Any pair of arguments `(long_name, short_name)` may be replaced with one of the following macros:\n\u003e - `CLAPX_ONLY_LONG(long_name)`\n\u003e - `CLAPX_ONLY_SHORT(short_name)`\n\n### Subcommands\nIn order to define subcommands, you will need to define the `CLAPX_SUBCOMMANDS` macro. Each subcommand will then be defined via the `CLAPX_SUBCOMMAND` macro, like this:\n```c\nvoid foo_callback(int argc, char** argv);\n\n#define CLAPX_SUBCOMMANDS \\\n    CLAPX_SUBCOMMAND(foo, \"foo\", \"The foo subcommand.\", foo_callback) \\\n    CLAPX_SUBCOMMAND(bar, \"bar\", CLAPX_NO_DESC, CLAPX_NO_CALLBACK, CLAPX_BOOL_FLAG(help, \"help\", 'h', CLAPX_NO_DESC, CLAPX_NO_CALLBACK))\n```\n\n#### List of macros for defining subcommands\n- `CLAPX_SUBCOMMAND(label, name, desc, callback, ...)`\n\nwhere...\n- `label` is a unique and valid C identifier.\n- `name` is a string literal.\n- `desc` is either a string literal or `CLAPX_NO_DESC`.\n- `callback` is a function pointer of type `clapx_subcommand_callback_t` or `CLAPX_NO_CALLBACK`. If set, this callback is triggered immediately after the command-line is completely parsed.\n- `...` are zero or more `CLAPX_FLAG` macros.\n\n### Parsing the command-line\nYou can parse the command-line, typically inside your main function, as follows:\n```c\nint main(int argc, char** argv)\n{\n    if (clapx_parse_args(argc, argv) != CLAPX_SUCCESS)\n    {\n        // Some internal parser error occured.\n        return EXIT_FAILURE;\n    }\n}\n```\n\n### Retrieving flag values\nMost likely, after parsing the command-line, you will want to inspect the value of a certain flag, since it may differ from the default value  if the user specified it.\nThe way this is done depends on whether the flag is global or subcommand-specific.\n\n**For global flags**: Use one of the `CLAPX_\u003ctype\u003e_FLAG_VALUE(flag)` macros, like this:\n```c\nint main(int argc, char** argv)\n{\n    // Retrieves the value of the global flag 'foo'.\n    const char* string_flag_value = CLAPX_STRING_FLAG_VALUE(foo);\n}\n```\n\n#### List of macros for retrieving global flag's values\n- `CLAPX_BOOL_FLAG_VALUE(flag)`\n- `CLAPX_U8_FLAG_VALUE(flag)`\n- `CLAPX_U16_FLAG_VALUE(flag)`\n- `CLAPX_U32_FLAG_VALUE(flag)`\n- `CLAPX_U64_FLAG_VALUE(flag)`\n- `CLAPX_I8_FLAG_VALUE(flag)`\n- `CLAPX_I16_FLAG_VALUE(flag)`\n- `CLAPX_I32_FLAG_VALUE(flag)`\n- `CLAPX_I64_FLAG_VALUE(flag)`\n- `CLAPX_CHAR_FLAG_VALUE(flag)`\n- `CLAPX_STRING_FLAG_VALUE(flag)`\n\nwhere...\n- `flag` is the label of the flag.\n\n**For subcommand-specific flags**: Use one of the `CLAPX_SUBCOMMAND_\u003ct\u003cpe\u003e_FLAG_VALUE(subcommand, flag)` macros, like this:\n```c\nvoid foo_callback(int argc, char** argv)\n{\n    // Retrieves the value of the 'bar' flag, which is bound to the 'foo' subcommand.\n    if (CLAPX_SUBCOMMAND_BOOL_FLAG_VALUE(foo, bar))\n    {\n        // ...\n    }\n    else\n    {\n        // ...\n    }\n}\n```\n\n#### List of macros for retrieving subcommand-specific flag's values\n- `CLAPX_SUBCOMMAND_BOOL_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_U8_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_U16_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_U32_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_U64_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_I8_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_I16_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_I32_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_I64_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_CHAR_FLAG_VALUE(subcommand, flag)`\n- `CLAPX_SUBCOMMAND_STRING_FLAG_VALUE(subcommand, flag)`\n\nwhere...\n- `subcommand` is the label of the subcommand.\n- `flag` is the label of the subcommand-specific flag.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoxmor%2Fclapx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoxmor%2Fclapx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoxmor%2Fclapx/lists"}