{"id":19691161,"url":"https://github.com/editso/cargparser","last_synced_at":"2026-05-26T16:33:06.058Z","repository":{"id":103282170,"uuid":"317552713","full_name":"editso/cargparser","owner":"editso","description":"c语言命令参数解析器","archived":false,"fork":false,"pushed_at":"2020-12-02T00:38:56.000Z","size":5,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T10:59:38.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/editso.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}},"created_at":"2020-12-01T13:38:45.000Z","updated_at":"2024-09-18T12:51:09.000Z","dependencies_parsed_at":"2023-10-15T08:34:55.585Z","dependency_job_id":null,"html_url":"https://github.com/editso/cargparser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/editso/cargparser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fcargparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fcargparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fcargparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fcargparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/editso","download_url":"https://codeload.github.com/editso/cargparser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fcargparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33529513,"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":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":"2024-11-11T19:08:14.427Z","updated_at":"2026-05-26T16:33:06.053Z","avatar_url":"https://github.com/editso.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 命令参数解析器 - cargparser\n简单命令参数解析器, 支持子命令,并且子命令可以继承父命令已有的命令\n\n### 列子\n`test/main.c`\n```\n#include \u003cstdio.h\u003e\n#include \"cargparser.h\"\n\n\n/**解析完成后的回调*/\nextern void server_cmd(cargparser_args* args);\nextern void client_cmd(cargparser_args* args);\n\nstruct option options[] = {\n/**      选项参数名             命令            描述信息      是否必须       默认值    */\n        {\"port\",        {\"-p\", \"--port\"},       0,           0,        \"8080\"},\n        {\"host\",        {\"-h\", \"--host\"},       0,           0,        \"3306\"}\n};\n\nstruct option server_options[] = {\n        {\"server\",      {\"-s\",\"--server\"} ,    0,            0,          0}\n};\n\nstruct option client_options[] = {\n        {\"client\",      {\"-c\",\"--client\"} ,    0,            0,          0}\n};\n\n\n// 子命令\ncargparser sub_cmd[] ={\n/**       命令             选项          选项数量               子命令    子命令数量      处理命令   */\n        {\"server\", server_options, len(server_options),         0,      0,       server_cmd},\n        {\"client\", client_options, len(client_options),         0,      0,       client_cmd},\n};\n\n/**\n * test server|client|stop\n * */\ncargparser parser = {\"test\", options, len(options), sub_cmd, len(sub_cmd)};\n\n\nint main(int argv, char **args){\n    cargparser_args arg;\n    parse_main(\u0026parser, \u0026arg, argv, args);\n    cargparser_call(\u0026arg);\n}\n\nextern void server_cmd(cargparser_args* args){\n    char *port = get_argument(args, \"port\", \"9999\");\n    char *host = get_argument(args, \"host\", \"255.255.255.255\");\n    char *server = get_argument(args, \"server\",\"\");\n    printf(\"port: %s\\n\", port);\n    printf(\"host: %s\\n\", host);\n    printf(\"server: %s\\n\", server);\n}\n\n\nextern void client_cmd(cargparser_args* args){\n    char *port = get_argument(args, \"port\", \"9999\");\n    char *host = get_argument(args, \"host\", \"255.255.255.255\");\n    char *client = get_argument(args, \"client\",\"\");\n    printf(\"port: %s\\n\", port);\n    printf(\"host: %s\\n\", host);\n    printf(\"client: %s\\n\", client);\n}\n```\n\n### 测试\n- **Input**:  \n`./test server -s 100 --host 0.0.0.0 --port 8080`\n- **Output**:  \n    ```\n    port: 8080\n    host: 0.0.0.0\n    server: 100\n    ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditso%2Fcargparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feditso%2Fcargparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditso%2Fcargparser/lists"}