{"id":29017867,"url":"https://github.com/cakephp/console","last_synced_at":"2025-06-25T23:07:19.244Z","repository":{"id":49822066,"uuid":"216956280","full_name":"cakephp/console","owner":"cakephp","description":"[Read only] Console libraries from CakePHP","archived":false,"fork":false,"pushed_at":"2025-05-17T03:08:10.000Z","size":1215,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-17T12:03:31.594Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cakephp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2019-10-23T03:02:34.000Z","updated_at":"2024-12-16T06:54:08.000Z","dependencies_parsed_at":"2023-09-28T10:09:59.254Z","dependency_job_id":"351e8504-f01d-409e-bc04-1846b19a052e","html_url":"https://github.com/cakephp/console","commit_stats":{"total_commits":912,"total_committers":64,"mean_commits":14.25,"dds":0.5932017543859649,"last_synced_commit":"7e259e9cd1c18026fd357a075f8368cabb67ad94"},"previous_names":[],"tags_count":118,"template":false,"template_full_name":null,"purl":"pkg:github/cakephp/console","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Fconsole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Fconsole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Fconsole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Fconsole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cakephp","download_url":"https://codeload.github.com/cakephp/console/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cakephp%2Fconsole/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261967132,"owners_count":23237663,"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":[],"created_at":"2025-06-25T23:07:17.382Z","updated_at":"2025-06-25T23:07:19.216Z","avatar_url":"https://github.com/cakephp.png","language":"PHP","readme":"[![Total Downloads](https://img.shields.io/packagist/dt/cakephp/http.svg?style=flat-square)](https://packagist.org/packages/cakephp/console)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt)\n\n# CakePHP Console Library\n\nThis library provides a framework for building command line applications from a\nset of commands. It provides abstractions for defining option and argument\nparsers, and dispatching commands.\n\n# installation\n\nYou can install it from Composer. In your project:\n\n```\ncomposer require cakephp/console\n```\n\n# Getting Started\n\nTo start, define an entry point script and Application class which defines\nbootstrap logic, and binds your commands. Lets put our entrypoint script in\n`bin/tool.php`:\n\n```php\n#!/usr/bin/php -q\n\u003c?php\n// Check platform requirements\nrequire dirname(__DIR__) . '/vendor/autoload.php';\n\nuse App\\Application;\nuse Cake\\Console\\CommandRunner;\n\n// Build the runner with an application and root executable name.\n$runner = new CommandRunner(new Application(), 'tool');\nexit($runner-\u003erun($argv));\n````\n\nFor our `Application` class we can start with:\n\n```php\n\u003c?php\nnamespace App;\n\nuse App\\Command\\HelloCommand;\nuse Cake\\Core\\ConsoleApplicationInterface;\nuse Cake\\Console\\CommandCollection;\n\nclass Application implements ConsoleApplicationInterface\n{\n    /**\n     * Load all the application configuration and bootstrap logic.\n     *\n     * @return void\n     */\n    public function bootstrap(): void\n    {\n        // Load configuration here. This is the first\n        // method Cake\\Console\\CommandRunner will call on your application.\n    }\n\n\n    /**\n     * Define the console commands for an application.\n     *\n     * @param \\Cake\\Console\\CommandCollection $commands The CommandCollection to add commands into.\n     * @return \\Cake\\Console\\CommandCollection The updated collection.\n     */\n    public function console(CommandCollection $commands): CommandCollection\n    {\n        $commands-\u003eadd('hello', HelloCommand::class);\n\n        return $commands;\n    }\n}\n```\n\nNext we'll build a very simple `HelloCommand`:\n\n```php\n\u003c?php\nnamespace App\\Command;\n\nuse Cake\\Console\\Arguments;\nuse Cake\\Console\\BaseCommand;\nuse Cake\\Console\\ConsoleIo;\nuse Cake\\Console\\ConsoleOptionParser;\n\nclass HelloCommand extends BaseCommand\n{\n    protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser\n    {\n        $parser\n            -\u003eaddArgument('name', [\n                'required' =\u003e true,\n                'help' =\u003e 'The name to say hello to',\n            ])\n            -\u003eaddOption('color', [\n                'choices' =\u003e ['none', 'green'],\n                'default' =\u003e 'none',\n                'help' =\u003e 'The color to use.'\n            ]);\n\n        return $parser;\n    }\n\n    public function execute(Arguments $args, ConsoleIo $io): ?int\n    {\n        $color = $args-\u003egetOption('color');\n        if ($color === 'none') {\n            $io-\u003eout(\"Hello {$args-\u003egetArgument('name')}\");\n        } elseif ($color == 'green') {\n            $io-\u003eout(\"\u003csuccess\u003eHello {$args-\u003egetArgument('name')}\u003c/success\u003e\");\n        }\n\n        return static::CODE_SUCCESS;\n    }\n}\n```\n\nNext we can run our command with `php bin/tool.php hello Syd`. To learn more\nabout the various features we've used in this example read the docs:\n\n* [Option Parsing](https://book.cakephp.org/4/en/console-commands/option-parsers.html)\n* [Input \u0026 Output](https://book.cakephp.org/4/en/console-commands/input-output.html)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakephp%2Fconsole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcakephp%2Fconsole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcakephp%2Fconsole/lists"}