{"id":18323005,"url":"https://github.com/jawira/mini-getopt","last_synced_at":"2025-04-05T23:31:20.563Z","repository":{"id":46632446,"uuid":"149331216","full_name":"jawira/mini-getopt","owner":"jawira","description":"Very simple wrapper for getopt() function","archived":false,"fork":false,"pushed_at":"2024-11-03T21:29:01.000Z","size":72,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T20:38:27.519Z","etag":null,"topics":["getopt","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/jawira.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-18T18:02:00.000Z","updated_at":"2024-11-03T21:27:16.000Z","dependencies_parsed_at":"2023-01-21T15:16:45.222Z","dependency_job_id":null,"html_url":"https://github.com/jawira/mini-getopt","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawira%2Fmini-getopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawira%2Fmini-getopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawira%2Fmini-getopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jawira%2Fmini-getopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jawira","download_url":"https://codeload.github.com/jawira/mini-getopt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415783,"owners_count":20935383,"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":["getopt","php"],"created_at":"2024-11-05T18:26:52.390Z","updated_at":"2025-04-05T23:31:15.555Z","avatar_url":"https://github.com/jawira.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mini Getopt (a getopt wrapper)\n==============================\n\nVery simple wrapper for `getopt()` function.\n\n[![Latest Stable Version](https://poser.pugx.org/jawira/mini-getopt/v)](//packagist.org/packages/jawira/mini-getopt)\n[![composer.lock](https://poser.pugx.org/jawira/mini-getopt/composerlock)](//packagist.org/packages/jawira/mini-getopt)\n[![.gitattributes](https://poser.pugx.org/jawira/mini-getopt/gitattributes)](//packagist.org/packages/jawira/mini-getopt)\n[![License](https://poser.pugx.org/jawira/mini-getopt/license)](//packagist.org/packages/jawira/mini-getopt)\n\nUsage\n-----\n\nThis is only a wrapper, therefore the output from `mini-getopt` is going to be \nthe same as `getopt()` function.\n\n1. First you have to instantiate `\\Jawira\\MiniGetopt\\MiniGetopt`. \n\n2. Then you have to configure options you want to use. To do so use the \nfollowing methods:\n\n    - `MiniGetopt::addRequired`.\n    - `MiniGetopt::addOptional`.\n    - `MiniGetopt::addNoValue`.\n\n3. To retrieve values you have to call one of the following method:\n\n    - `MiniGetopt::getopt` returns the same as `getopt()`. Optionally you  can pass `$optind` parameter.\n    - `MiniGetopt::getOption` to get only one value.\n    - `MiniGetopt::doc` get documentation.\n\nBasic usage\n-----------\n\nPHP code:\n\n```php\n// resources/example.php\n// Preparing options\n$mg = new \\Jawira\\MiniGetopt\\MiniGetopt();\n$mg-\u003eaddRequired('f', 'format');    // value is required\n$mg-\u003eaddOptional('r', 'retry');     // value is optional\n$mg-\u003eaddOptional('q', '');          // only short option\n$mg-\u003eaddNoValue('v', 'verbose');    // no value\n$mg-\u003eaddNoValue('', 'version');     // only long option\n\n// Calling getopt\nvar_export($mg-\u003egetopt());\n```\n\nExecuting code:\n\n```console\n$ php resources/example.php\n\narray (\n)\n```\n\n```console\n$ php resources/example.php -f=xml\n\narray (\n   'f' =\u003e 'xml',\n)\n```\n\n```console\n$ php resources/example.php --format=xml -r -v\n\narray (\n  'format' =\u003e 'xml',\n  'r' =\u003e false,\n  'v' =\u003e false,\n)\n```\n\n```console\n$ php resources/example.php -f=json -r=yes -v\n\narray (\n    'f' =\u003e 'json',\n    'r' =\u003e 'yes',\n    'v' =\u003e false,\n)\n```\n\n```console\n$ php resources/example.php --retry -vvv\n\narray (\n  'retry' =\u003e false,\n  'v' =\u003e \n  array (\n    0 =\u003e false,\n    1 =\u003e false,\n    2 =\u003e false,\n  ),\n)\n```\n\n```console\n$ php resources/example.php --version=banana --invalid\n\narray (\n  'version' =\u003e false,\n)\n```\n\n`optind` parameter\n------------------\n\n```php\n// Setup\n$mg = new \\Jawira\\MiniGetopt\\MiniGetopt();\n$mg-\u003eaddRequired('f', 'format');\n$mg-\u003eaddNoValue('v', 'verbose');\n\n// Calling getopt function with `optind` parameter\n$optind = null;\n$options = $mg-\u003egetopt($optind);\necho \"optind: $optind\" . PHP_EOL;\n```\n\n```console\n$ php resources/example.php --format=pdf -vv\noptind: 3\n```\n\nGenerate doc\n------------\n\n```php\n$mg = new \\Jawira\\MiniGetopt\\MiniGetopt();\n$mg-\u003eaddRequired('f', 'format', 'Format to export', 'png|gif|svg');\n$mg-\u003eaddOptional('r', 'retry', 'Retry on error', 'count');\n$mg-\u003eaddOptional('q', '', 'Quiet mode', 'yes|no');\n$mg-\u003eaddNoValue('v', 'verbose', 'Display verbose messages');\n$mg-\u003eaddNoValue('', 'version', 'Show version');\necho $mg-\u003edoc();\n```\n\n```console\n$ php resource/example.php\nOPTIONS\n\n-f, --format=\u003cpng|gif|svg\u003e\nFormat to export\n\n-r, --retry=[count]\nRetry on error\n\n-q=[yes|no]\nQuiet mode\n\n-v, --verbose\nDisplay verbose messages\n\n--version\nShow version\n\n```\n\n\nHow to install\n--------------\n\n```console\n$ composer install jawira/mini-getopt\n```\n\nContributing\n------------\n\nIf you liked this project, ⭐ star it on [GitHub][].\n\nLicense\n-------\n\nThis library is licensed under the [MIT license](LICENSE.md).\n\n\n***\n\nPackages from jawira\n--------------------\n\n\u003cdl\u003e\n\n\u003cdt\u003e\n    \u003ca href=\"https://packagist.org/packages/jawira/emoji-catalog\"\u003ejawira/emoji-catalog\n    \u003cimg alt=\"GitHub stars\" src=\"https://badgen.net/github/stars/jawira/emoji-catalog?icon=github\"/\u003e\u003c/a\u003e\n\u003c/dt\u003e\n\u003cdd\u003eGet access to +3000 emojis as class constants.\u003c/dd\u003e\n\n\u003cdt\u003e\n    \u003ca href=\"https://packagist.org/packages/jawira/plantuml-encoding\"\u003e jawira/plantuml-encoding\n    \u003cimg alt=\"GitHub stars\" src=\"https://badgen.net/github/stars/jawira/plantuml-encoding?icon=github\"/\u003e\u003c/a\u003e\n\u003c/dt\u003e\n\u003cdd\u003ePlantUML encoding functions.\u003c/dd\u003e\n\n\u003cdt\u003e\n    \u003ca href=\"https://packagist.org/packages/jawira/case-converter\"\u003ejawira/case-converter \n    \u003cimg alt=\"GitHub stars\" src=\"https://badgen.net/github/stars/jawira/case-converter?icon=github\"/\u003e\u003c/a\u003e\n\u003c/dt\u003e\n\u003cdd\u003eConvert strings between 13 naming conventions: Snake case, Camel case,\n  Pascal case, Kebab case, Ada case, Train case, Cobol case, Macro case,\n  Upper case, Lower case, Sentence case, Title case and Dot notation.\n\u003c/dd\u003e\n\n\u003cdt\u003e\u003ca href=\"https://packagist.org/packages/jawira/\"\u003emore...\u003c/a\u003e\u003c/dt\u003e\n\u003c/dl\u003e\n\n[Github]: https://github.com/jawira/mini-getopt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjawira%2Fmini-getopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjawira%2Fmini-getopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjawira%2Fmini-getopt/lists"}