{"id":20426417,"url":"https://github.com/zbanks/optim","last_synced_at":"2026-03-09T08:02:38.571Z","repository":{"id":137628221,"uuid":"88291042","full_name":"zbanks/optim","owner":"zbanks","description":"Immediate-mode command line option parsing for C","archived":false,"fork":false,"pushed_at":"2017-05-09T00:51:16.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T16:40:36.706Z","etag":null,"topics":["c","options"],"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/zbanks.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}},"created_at":"2017-04-14T18:05:33.000Z","updated_at":"2020-03-20T22:32:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c229121-78cd-4f50-94e3-129943d06f84","html_url":"https://github.com/zbanks/optim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zbanks/optim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbanks%2Foptim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbanks%2Foptim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbanks%2Foptim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbanks%2Foptim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbanks","download_url":"https://codeload.github.com/zbanks/optim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbanks%2Foptim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30287447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"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":["c","options"],"created_at":"2024-11-15T07:16:32.530Z","updated_at":"2026-03-09T08:02:38.543Z","avatar_url":"https://github.com/zbanks.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/zbanks/optim.svg?branch=master)](https://travis-ci.org/zbanks/optim)\n\n# `optim`\nImmediate-mode command line option parsing for C.\n\n## Features\n\n- Immediate-mode: declare, read, and validate locally\n- Auto-generated usage message (``--help``)\n- Options parsing can be split over multiple functions\n- Supports long and short options, with and without arguments\n- Supports positional arguments and `--`\n- Supports repeated arguments\n- Plays nice with `help2man`\n- Doesn't rely on macros or preprocessor trickery\n- Opinionated only when it makes things simpler\n\n### Example Generated Usage\n\nSee ``test/main.c``\n\n```\nUsage: optim_test [-a] [-b] \u003cpath\u003e\n\nMy test optim program\n\nOptions:\n  -h, --help                  Print this help message\n  -v, --verbose               Increase verbosity\n\nSection Two:\n  -a, --alpha=ARG             Alpha parameter. This usage has a lot to say, so\n                                the usage spans over multiple lines\n                                Newlines are also handled fine\n  -b, --beta                  Beta flag\n  -c                          C flag without longform\n      --delta=diff            Delta parameter without short form\n  -e exarg                    Extra option with an arg but no longopt\n```\n\n### Supported Formats\n\nEach line shows options that are parsed equivalently by `optim`.\n\n- `-v`, `--verbose`\n- `-vvv`, `-v -v -v`, `--verbose -vv`\n- `-a ARG`, `--alpha ARG`, `--alpha=ARG`\n- `-va ARG`, `-v -a ARG`, `--verbose --alpha ARG`\n\n### Unsupported Formats\n\nThe following examples are *not* parsed correctly by `optim`.\n\n- `-aARG`\n- `-a=ARG`\n- `-beta`\n- `--alpha -ARG`, use `--alpha=-ARG` if your argument could begin with a `-`\n\nAlso, `optim` does not currently support:\n\n- Optional arguments (`--alpha[=ARG]`)\n- Suboptions (`-o,rw`) \n- Subcommands (`git show`)\n\n## Example\n\n```\nint main(int argc, char ** argv) {\n    optim_t * o = optim_start(argc, argv, \"%s [-a] [-b|-c] \u003cpath\u003e\");\n    if (o == NULL) exit(EXIT_FAILURE);\n\n    optim_usage(o, \"My test optim program\\n\");\n    optim_version(o, \"optim_test Version 1.0\\nAuthor: Zach Banks\\n\");\n\n    optim_flag(o, 'v', \"verbose\", \"Increase verbosity\");\n    int verbosity = optim_get_count(o);\n\n    optim_usage(o, \"\\nSection Two:\\n\");\n\n    optim_arg(o, 'a', \"alpha\", NULL, \"Alpha parameter\");\n    long alpha = optim_get_long(o, 0);\n    \n    optim_flag(o, 'b', \"beta\", \"Beta flag\");\n    bool beta = optim_get_count(o) \u003e 0;\n\n    optim_flag(o, 'c', NULL, \"C flag without longform\");\n    bool cflag = optim_get_count(o) \u003e 0;\n\n    if (cflag \u0026\u0026 beta)\n        optim_error(\"cannot specify both -b and -c flags\");\n\n    optim_positionals(o);\n    char * path = optim_get_string(o, NULL);\n    if (path == NULL)\n        optim_error(o, \"must specify path\");\n\n    int rc = optim_finish(\u0026o);\n    if (rc \u003c 0) exit(EXIT_FAILURE);\n\n    // ...\n}\n```\n\n## About\n\n`optim` is licensed under the MIT license. Copyright (c) 2017 Zach Banks.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbanks%2Foptim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbanks%2Foptim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbanks%2Foptim/lists"}