{"id":16768506,"url":"https://github.com/theofidry/console","last_synced_at":"2025-04-07T12:10:55.679Z","repository":{"id":36993430,"uuid":"363895128","full_name":"theofidry/console","owner":"theofidry","description":"Library for creating CLI commands or applications","archived":false,"fork":false,"pushed_at":"2025-02-14T11:09:04.000Z","size":602,"stargazers_count":19,"open_issues_count":10,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-31T11:05:36.779Z","etag":null,"topics":["cli","console","symfony"],"latest_commit_sha":null,"homepage":"","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/theofidry.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["theofidry"]}},"created_at":"2021-05-03T10:37:00.000Z","updated_at":"2025-02-14T11:06:19.000Z","dependencies_parsed_at":"2024-10-26T21:12:49.131Z","dependency_job_id":"1a56f2ab-d3b4-4e5e-84dd-212aac841168","html_url":"https://github.com/theofidry/console","commit_stats":{"total_commits":115,"total_committers":4,"mean_commits":28.75,"dds":"0.34782608695652173","last_synced_commit":"e77e04c8e5c707e29a059ed4725f7f6e9d94cb48"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theofidry%2Fconsole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theofidry%2Fconsole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theofidry%2Fconsole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theofidry%2Fconsole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theofidry","download_url":"https://codeload.github.com/theofidry/console/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"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":["cli","console","symfony"],"created_at":"2024-10-13T06:11:46.662Z","updated_at":"2025-04-07T12:10:55.652Z","avatar_url":"https://github.com/theofidry.png","language":"PHP","funding_links":["https://github.com/sponsors/theofidry"],"categories":[],"sub_categories":[],"readme":"\n## Console\n\nMotivation: this library purpose is to provide a lighter and more robust API\nfor console commands and/or applications to [symfony/console][SymfonyConsole].\n\nIt can be used either in combination with [`FrameworkBundle`][FrameworkBundle] to\nfacilitate the creation of commands or as a stand-alone package to create a CLI\napplication app.\n\nKey differences:\n\n- Leverages an `IO` object instead of Input + Output + SymfonyStyle which offers:\n    - The API of SymfonyStyle but still access to the Input and Output objects\n    - A typed API for arguments and options (the input is validated when\n      coercing it to a stricter type)\n- Implement explicit interfaces instead of extending god classes\n\n\n## Table of Contents\n\n- [Installation with Symfony](#installation-with-symfony)\n- [Usage preview](#usage-preview)\n- [Complete documentation](#complete-documentation)\n    - [Command](./doc/command.md)\n        - [Creating a command](./doc/command.md#creating-a-command)\n        - [Configuring the Command](./doc/command.md#configuring-the-command)\n        - [Registering the Command](./doc/command.md#registering-the-command)\n        - [Executing the Command](./doc/command.md#executing-the-command)\n        - [Console Output](./doc/command.md#console-output)\n        - [Output Sections](./doc/command.md#output-sections)\n        - [Console Input](./doc/command.md#console-input)\n        - [Getting Services from the Service Container](./doc/command.md#getting-services-from-the-service-container)\n        - [Command Lifecycle](./doc/command.md#command-lifecycle)\n        - [Testing Commands](./doc/command.md#testing-commands)\n        - [Logging Command Errors](./doc/command.md#logging-command-errors)\n        - [Learn More](./doc/command.md#learn-more)\n    - [How to Call Other Commands](./doc/call-other-commands.md)\n    - [How to Make Commands Lazily Loaded](./doc/lazy-command.md)\n    - [Application](./doc/application.md)\n        - [Creating an application](./doc/application.md#creating-an-application)\n        - [Executing an Application](./doc/application.md#executing-an-application)\n    - [Testing](./doc/testing.md)\n        - [Testing an Application](./doc/testing.md#testing-an-application)\n        - [Testing a Command](./doc/testing.md#testing-a-command)\n- [Known Limitations](#known-limitations)\n- [Inspirations](#inspirations)\n- [Contributing](#contributing)\n\n\n### Installation with Symfony\n\n```\n$ composer require theofidry/console\n```\n\nThe Symfony Flex plugin should add the following:\n\n```php\n\u003c?php declare(strict_types=1);\n// config/bundles.php\n\nreturn [\n    // ...\n    // Symfony\\Bundle\\FrameworkBundle\\Symfony\\Bundle\\FrameworkBundle()\n    // ...\n    Fidry\\Console\\FidryConsoleBundle::class =\u003e ['all' =\u003e true],\n];\n\n```\n\n### Usage preview\n\nTo implement a command you have to implement the `Fidry\\Console\\Command\\Command` interface as\nfollows:\n\n```php\n\u003c?php declare(strict_types=1);\n\nnamespace Acme;\n\nuse Acme\\MyService;\nuse Fidry\\Console\\{ Command\\Command, Command\\Configuration, ExitCode, IO };\nuse Symfony\\Component\\Console\\Input\\InputArgument;\n\nfinal class CommandWithService implements Command\n{\n    private MyService $service;\n\n    public function __construct(MyService $service)\n    {\n        $this-\u003eservice = $service;\n    }\n\n    public function getConfiguration(): Configuration\n    {\n        return new Configuration(\n            'app:foo',\n            'Calls MyService',\n            \u003c\u003c\u003c'EOT'\n            The \u003cinfo\u003e%command.name\u003c/info\u003e command calls MyService\n            EOT,\n            [\n                new InputArgument(\n                    'username',\n                    InputArgument::REQUIRED,\n                    'Name of the user',\n                ),\n                new InputArgument(\n                    'age',\n                    InputArgument::OPTIONAL,\n                    'Age of the user',\n                ),\n            ],\n        );\n    }\n\n    public function execute(IO $io): int\n    {\n        $this-\u003eservice-\u003ecall(\n            $io-\u003egetTypedArgument('username')-\u003easStringNonEmptyList(),\n            $io-\u003egetTypedArgument('age')-\u003easNullablePositiveInteger(),\n        );\n\n        return ExitCode::SUCCESS;\n    }\n}\n```\n\nWith the bundle enabled, those services are auto-configured into traditional Symfony commands.\n\n\n### Known limitations\n\nSome limitations are due to lack of time dedicated to those or based on\nthe assumption they are not necessary. Those choices may be revisited depending on\nof the use case presented.\n\n- Support for hidden commands ([see doc][hidden-commands])\n- Support for command aliases\n- Support for command usage configuration\n- Some obscure methods of `Application`\n\n\n### Inspirations\n\n- [zenstruck/console-extra](https://github.com/zenstruck/console-extra)\n- [zenstruck/console-test](https://github.com/zenstruck/console-test)\n- [webignition/symfony-console-typed-input](https://github.com/webignition/symfony-console-typed-input)\n- [webmozart-console](https://github.com/webmozart/console)\n\n\n### Contributing\n\nThe project provides a `Makefile` in which the most common commands have been\nregistered such as fixing the coding style or running the test.\n\n```bash\n# Print the list of available commands\nmake\n# or\nmake help\n```\n\n\n[hidden-commands]: https://symfony.com/doc/current/console/hide_commands.html\n[FrameworkBundle]: https://github.com/symfony/framework-bundle\n[SymfonyConsole]: https://github.com/symfony/console\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheofidry%2Fconsole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheofidry%2Fconsole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheofidry%2Fconsole/lists"}