{"id":25089590,"url":"https://github.com/azersd/argparse","last_synced_at":"2025-10-11T05:39:30.206Z","repository":{"id":274697168,"uuid":"923772409","full_name":"AzerSD/argparse","owner":"AzerSD","description":"CLI Argument parser in C for 42 projects.","archived":false,"fork":false,"pushed_at":"2025-01-28T20:18:00.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T11:17:49.749Z","etag":null,"topics":["42","42cursus","42projects","argparse","c","cli"],"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/AzerSD.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}},"created_at":"2025-01-28T20:00:11.000Z","updated_at":"2025-01-29T10:26:03.000Z","dependencies_parsed_at":"2025-01-28T21:24:35.458Z","dependency_job_id":"954c5b8b-3711-4d5e-9d97-e9d06e8f6982","html_url":"https://github.com/AzerSD/argparse","commit_stats":null,"previous_names":["azersd/argparse"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzerSD%2Fargparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzerSD%2Fargparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzerSD%2Fargparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzerSD%2Fargparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AzerSD","download_url":"https://codeload.github.com/AzerSD/argparse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246679068,"owners_count":20816402,"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","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":["42","42cursus","42projects","argparse","c","cli"],"created_at":"2025-02-07T11:17:57.917Z","updated_at":"2025-10-11T05:39:25.175Z","avatar_url":"https://github.com/AzerSD.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# argparse\n\nThis repository contains a simple argument parser implementation in C. The parser supports parsing command-line options and positional arguments, providing a flexible framework for handling various types of inputs. I'm making this mainly to use for 42 Mastery projects where a lot of projects require parsing arguments.\n\n## Getting Started\n\n### Prerequisites\n\n- GCC or any C compiler.\n- Basic understanding of command-line argument parsing.\n\n### Compilation\n\nTo compile the program, run the following command:\n\n```bash\ngcc -o argparse argparse.c\n```\n\n### Usage\n\nHere is an example usage of the compiled program:\n\n```bash\n./argparse -v -c 5 -n \"Example Name\" arg1 arg2 arg3\n```\n\n### Example Output\n\n```bash\nVerbose: 1\nCount: 5\nName: Example Name\nPositional arguments:\n  arg1\n  arg2\n  arg3\n```\n\n## Code Explanation\n\n### Key Components\n\n1. **Option Structure (`Option`)**:\n   - Defines the flags, their types, and associated values.\n2. **Argument Parser (`ArgParser`)**:\n   - Manages the list of options and positional arguments.\n3. **Initialization and Parsing Functions**:\n   - `init_arg_parser`: Initializes the parser.\n   - `add_option`: Adds a new option to the parser.\n   - `parse_arguments`: Parses command-line arguments and assigns values to the appropriate variables.\n\n### Adding Options\n\nUse the `add_option` function to define options:\n\n```c\nadd_option(\u0026parser, \"-v\", \"--verbose\", ARGTYPE_FLAG, \u0026verbose);\nadd_option(\u0026parser, \"-c\", \"--count\", ARGTYPE_INT, \u0026count);\nadd_option(\u0026parser, \"-n\", \"--name\", ARGTYPE_STRING, \u0026name);\n```\n\n- `-v` / `--verbose`: A flag option that sets `verbose` to `1` when provided.\n- `-c` / `--count`: An integer option that assigns a value to `count`.\n- `-n` / `--name`: A string option that assigns a value to `name`.\n\n### Parsing Arguments\n\nCall `parse_arguments` with `argc` and `argv`:\n\n```c\nparse_arguments(\u0026parser, argc, argv);\n```\n\nThis function matches provided arguments against the defined options and handles positional arguments.\n\n### Displaying Usage\n\nUse the `print_usage` function to display all supported options:\n\n```c\nprint_usage(\u0026parser);\n```\n\n## Limitations\n\n- Maximum of 20 options and 20 positional arguments (can be adjusted by modifying `MAX_OPTIONS` and `MAX_POSITIONAL`).\n- Does not support default values for options.\n- No advanced error handling for malformed arguments.\n\n## Contributing\n\nContributions are welcome! Feel free to open issues or submit pull requests to improve this project.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazersd%2Fargparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazersd%2Fargparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazersd%2Fargparse/lists"}