{"id":20842235,"url":"https://github.com/lijinma/commander","last_synced_at":"2025-05-08T22:41:33.571Z","repository":{"id":25018709,"uuid":"28438012","full_name":"lijinma/Commander","owner":"lijinma","description":"PHP command-line interfaces made easy","archived":false,"fork":false,"pushed_at":"2020-02-20T09:38:02.000Z","size":22,"stargazers_count":14,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T19:05:04.071Z","etag":null,"topics":["command","console","php-command","php-console"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/lijinma.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}},"created_at":"2014-12-24T06:21:10.000Z","updated_at":"2024-12-04T19:42:45.000Z","dependencies_parsed_at":"2022-08-23T12:02:46.657Z","dependency_job_id":null,"html_url":"https://github.com/lijinma/Commander","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lijinma%2FCommander","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lijinma%2FCommander/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lijinma%2FCommander/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lijinma%2FCommander/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lijinma","download_url":"https://codeload.github.com/lijinma/Commander/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253160727,"owners_count":21863624,"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":["command","console","php-command","php-console"],"created_at":"2024-11-18T01:23:34.568Z","updated_at":"2025-05-08T22:41:33.556Z","avatar_url":"https://github.com/lijinma.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Commander\n=========\n\nThe solution for php command-line interfaces, inspired by [commander](https://github.com/tj/commander.js) in Node.js.\n\nActually some funtions in Commander is refer to [commander](https://github.com/tj/commander.js), so really thank TJ.\n\n\n## Installation\n\n    $ composer require \"lijinma/commander\"\n    \n## Option parsing\n\nOptions with commander are defined with the `option()` method, also serving as documentation for the options. The example below parses args and options from `$argv`.\n\n```php\n\n\u003c?php\n\nuse Lijinma\\Commander;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n$cmd = new Commander();\n\n$cmd\n    -\u003eversion('0.0.1')\n    -\u003eoption('-p, --peppers', 'Add peppers')\n    -\u003eoption('-P, --pineapple', 'Add pineapple')\n    -\u003eoption('-b, --bbq', 'Add bbq sauce')\n    -\u003eoption('-c, --cheese [type]', 'Add the specified type of cheese')\n    -\u003eparse($argv);\n\n\necho 'you ordered a pizza with:' . PHP_EOL;\nif (isset($cmd-\u003epeppers)) {\n    echo '  - peppers' . PHP_EOL;\n}\nif (isset($cmd-\u003epineapple)) {\n    echo '  - pineapple' . PHP_EOL;\n}\nif (isset($cmd-\u003ebbq)) {\n    echo '  - bbq' . PHP_EOL;\n}\n\nif (isset($cmd-\u003echeese)) {\n    echo \"  - $cmd-\u003echeese cheese\" . PHP_EOL;\n}\n\n```\n\n![](https://raw.githubusercontent.com/lijinma/MyBox/master/commander1.png)\n\nShort flags may be passed as a single arg, for example -abc is equivalent to -a -b -c.\n\n## Sub commands\n\n```php\n\u003c?php\n\nuse Lijinma\\Commander;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n$cmd = new Commander();\n\n$cmd\n    -\u003eversion('0.0.1')\n    -\u003ecommand('rmdir \u003cdir\u003e [otherDirs...]', 'Remove the directory')\n    -\u003eaction(\n        function ($dir, $otherDirs) {\n            echo 'You will remove the following directory: ' . $dir . PHP_EOL;\n            if ($otherDirs) {\n                echo 'And other directories: ' . implode(', ', $otherDirs) . PHP_EOL;\n            }\n        }\n    );\n\n$cmd-\u003ecommand('rm \u003cfile\u003e', 'Remove a file')\n    -\u003eaction(\n        function ($file) {\n            echo 'You will remove the following file: ' . $file . PHP_EOL;\n        }\n    );\n\n$cmd-\u003eparse($argv);\n```\n![](https://raw.githubusercontent.com/lijinma/MyBox/master/commander2.png)\n\nEvery command has one action.\n\n##Automated --help\n\nI really don't like the help generated by Symfony/Console, it's complicated and heavy.\n\n```\n  Usage: test.php [options]\n\n  Commands:\n\n    rmdir \u003cdir\u003e [otherDirs...]    Remove the directory\n    rm \u003cfile\u003e                     Remove a file\n\n  Options:\n\n    -h, --help  Output usage information\n```\n\n## Test Commander\n\nI use [PHPSpec](http://www.phpspec.net) to do unit test. PHPSpec is an awesome test framework.\n\n```\n    $ composer install\n    $ phpspec run\n```\n\n\n##License\n\nCommander is released under the MIT license:\n\n\u003e The MIT License\n\u003e\n\u003e Copyright (c) 2014 Jinma Li \\\u003c lijinma@126.com \\\u003e\n\u003e\n\u003e Permission is hereby granted, free of charge, to any person obtaining a copy\n\u003e of this software and associated documentation files (the \"Software\"), to deal\n\u003e in the Software without restriction, including without limitation the rights\n\u003e to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\u003e copies of the Software, and to permit persons to whom the Software is\n\u003e furnished to do so, subject to the following conditions:\n\u003e\n\u003e The above copyright notice and this permission notice shall be included in\n\u003e all copies or substantial portions of the Software.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\u003e IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\u003e FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\u003e AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\u003e LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\u003e OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n\u003e THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flijinma%2Fcommander","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flijinma%2Fcommander","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flijinma%2Fcommander/lists"}