{"id":16987236,"url":"https://github.com/yorickpeterse/inko-optparse","last_synced_at":"2026-03-06T04:30:17.455Z","repository":{"id":193403650,"uuid":"688707237","full_name":"yorickpeterse/inko-optparse","owner":"yorickpeterse","description":"An Inko library for parsing command-line arguments and options","archived":true,"fork":false,"pushed_at":"2024-02-01T00:52:01.000Z","size":46,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T20:13:38.263Z","etag":null,"topics":["argument-parsing","cli","getopt","getopts","inko","option-parser"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yorickpeterse.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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},"funding":{"github":"yorickpeterse"}},"created_at":"2023-09-07T23:55:48.000Z","updated_at":"2024-06-30T08:24:42.000Z","dependencies_parsed_at":"2023-10-15T20:10:01.372Z","dependency_job_id":"177009c3-2a7e-46c7-a58b-f14bf7557e60","html_url":"https://github.com/yorickpeterse/inko-optparse","commit_stats":null,"previous_names":["yorickpeterse/inko-optparse"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Finko-optparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Finko-optparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Finko-optparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorickpeterse%2Finko-optparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yorickpeterse","download_url":"https://codeload.github.com/yorickpeterse/inko-optparse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239892167,"owners_count":19714264,"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":["argument-parsing","cli","getopt","getopts","inko","option-parser"],"created_at":"2024-10-14T02:48:42.536Z","updated_at":"2026-03-06T04:30:17.360Z","avatar_url":"https://github.com/yorickpeterse.png","language":"Makefile","funding_links":["https://github.com/sponsors/yorickpeterse"],"categories":[],"sub_categories":[],"readme":"# inko-optparse\n\nAn opinionated and lightweight command-line argument and option parser for\n[Inko](https://inko-lang.org), inspired by getopts, with full support for\nUnicode options.\n\nBoth short and long options are supported, using the syntax `-o` and `--option`\nfor short and long options respectively. Long option pairs (`--option=value`)\nare also supported. Short option pairs (`-o=v`) are parsed such that the value\nincludes the `=`, so `-o=v` is parsed the same way as `-o \"=v\"`. There are no\nplans to support parsing these such that the value doesn't include the `=` (i.e.\nparsing `-o=v` as `-o v`).\n\nShort option names are restricted to single extended grapheme clusters\n(\"characters\"), meaning `-foo` isn't a valid option. Long option names must\ncontain at least two characters, so `--h` isn't a valid option.\n\ninko-optparse supports parsing `--` as an argument. Upon encountering this\nargument, all arguments that followed are kept as-is. This allows passing these\narguments to subcommands or other processes.\n\n# Requirements\n\n- Inko 0.13.2 or newer\n\n# Installation\n\n```bash\ninko pkg add github.com/yorickpeterse/inko-optparse 0.4.0\ninko pkg sync\n```\n\n# Usage\n\nThe type `optparse.Options` is used to define options, using the methods\n`Options.flag` for flags (e.g. `-h`/`--help`), `Options.single` for options that\nrequire a single value (e.g. `--config=foo.json`), and `Options.multiple` for\noptions that accept multiple values (e.g. `--include=foo --include=bar`).\n\nOnce your options are defined, you can parse a list of arguments (e.g. the\nreturn value of `std.env.arguments`) into a `Matches` type using\n`Options.parse`:\n\n```inko\nimport optparse.Options\nimport std.env\n\nclass async Main {\n  fn async main {\n    let opts = Options.new\n\n    opts.flag('h', 'help', 'Show this help message')\n\n    let matches = opts.parse(env.arguments).unwrap\n  }\n}\n```\n\nUsing `Matches.contains?` you can check if an option is specified, using either\nthe short or long name. `Matches.value` returns the first argument of an option\n(provided it accepts arguments), while `Matches.values` returns all the\narguments specified. Any remaining arguments are stored in `Matches.remaining`.\n\nBy default, `Options` parses any options it encounters and will throw an error\nfor any invalid options. The option `Options.stop_at_first_non_option` can be\nused to customize this behaviour: when set to `true`, the first value\nencountered that isn't an option argument results in it and any arguments that\nfollow it being stored in `Matches.remaining`:\n\n```inko\nimport optparse.Options\nimport std.env\nimport std.fmt.(fmt)\nimport std.stdio.STDOUT\n\nclass async Main {\n  fn async main {\n    let opts = Options.new\n\n    opts.flag('h', 'help', 'Show this help message')\n    opts.stop_at_first_non_option = true\n\n    let matches = opts.parse(env.arguments).unwrap\n\n    STDOUT.new.print(fmt(matches.remaining))\n  }\n}\n```\n\nWhen run with the command-line arguments `['foo', '--bar']`, instead of\nproducing an error (or panic in the case of this example, due to the `unwrap`),\nthe output is `['foo', '--bar']`. This is useful if you want to support\nsubcommands with their own options, using the syntax\n`root-command --root-option [...] sub-command --sub-option [...]`.\n\nHere's a more in-depth example of using inko-optparse, including displaying a\nusage message and the available options:\n\n```inko\nimport optparse.(Help, Options)\nimport std.env\nimport std.fmt.(fmt)\nimport std.stdio.(STDOUT, STDERR)\nimport std.sys\n\nclass async Main {\n  fn async main {\n    let opts = Options.new\n\n    opts.flag('h', 'help', 'Show this help message')\n    opts.single('c', 'config', 'PATH', 'Use a custom configuration file')\n    opts.multiple('i', 'include', 'DIR', 'Add the directory')\n    opts.multiple('I', 'ignore', '', 'Ignore something')\n    opts.flag('', 'verbose', \"Use verbose output,\\nlorem ipsum\")\n    opts.flag('', 'example', '')\n    opts.flag('x', '', 'Foo')\n\n    let matches = match opts.parse(env.arguments) {\n      case Ok(v) -\u003e v\n      case Error(e) -\u003e {\n        STDERR.new.print(\"test: {e}\")\n        sys.exit(1)\n      }\n    }\n\n    if matches.contains?('help') {\n      let help = Help\n        .new('test')\n        .description(\n          'This is an example program to showcase the optparse library.'\n        )\n        .section('Examples')\n        .line('test --help')\n        .section('Options')\n        .options(opts)\n        .to_string\n\n      STDOUT.new.write_string(help)\n    } else {\n      STDOUT.new.print(fmt(matches.remaining))\n    }\n  }\n}\n```\n\nWhen running this program and providing the `--help` option, the output is:\n\n```\nUsage: test [OPTIONS]\n\nThis is an example program to showcase the optparse library.\n\nExamples:\n\n  test --help\n\nOptions:\n\n  -h, --help           Show this help message\n  -c, --config=PATH    Use a custom configuration file\n  -i, --include=DIR    Add the directory\n  -I, --ignore         Ignore something\n      --verbose        Use verbose output,\n                       lorem ipsum\n      --example\n  -x                   Foo\n```\n\n# License\n\nAll source code in this repository is licensed under the Mozilla Public License\nversion 2.0, unless stated otherwise. A copy of this license can be found in the\nfile \"LICENSE\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyorickpeterse%2Finko-optparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyorickpeterse%2Finko-optparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyorickpeterse%2Finko-optparse/lists"}