{"id":19433171,"url":"https://github.com/ssnepenthe/apheleia-cli","last_synced_at":"2025-04-24T20:31:25.827Z","repository":{"id":41483818,"uuid":"457489935","full_name":"ssnepenthe/apheleia-cli","owner":"ssnepenthe","description":"An alternative syntax for writing WP-CLI commands","archived":false,"fork":false,"pushed_at":"2024-03-20T21:06:59.000Z","size":146,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T20:17:49.272Z","etag":null,"topics":["toy","wordpress"],"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/ssnepenthe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2022-02-09T18:57:03.000Z","updated_at":"2023-01-19T07:19:02.000Z","dependencies_parsed_at":"2024-03-20T22:26:18.083Z","dependency_job_id":null,"html_url":"https://github.com/ssnepenthe/apheleia-cli","commit_stats":{"total_commits":61,"total_committers":1,"mean_commits":61.0,"dds":0.0,"last_synced_commit":"da6e3d157225e81c75c442b683ab5294a28530fc"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnepenthe%2Fapheleia-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnepenthe%2Fapheleia-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnepenthe%2Fapheleia-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssnepenthe%2Fapheleia-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssnepenthe","download_url":"https://codeload.github.com/ssnepenthe/apheleia-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250704622,"owners_count":21473732,"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":["toy","wordpress"],"created_at":"2024-11-10T14:38:41.100Z","updated_at":"2025-04-24T20:31:25.565Z","avatar_url":"https://github.com/ssnepenthe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# apheleia-cli\n\nApheleia CLI provides an alternate approach to writing WP-CLI commands. It eliminates the need for docblock command definitions and should allow you to take full advantage of the autocomplete features in your favorite editor.\n\nThe syntax for Apheleia commands is loosely modeled after the [symfony/console](https://github.com/symfony/console) package.\n\n## Warning\n\nThis package is currently in development and is subject to breaking changes without notice until v1.0 has been tagged.\n\nIt is one in a series of [WordPress toys](https://github.com/ssnepenthe?tab=repositories\u0026q=topic%3Atoy+topic%3Awordpress\u0026type=\u0026language=\u0026sort=) I have been working on with the intention of exploring ways to modernize the feel of working with WordPress.\n\nAs the label suggests, it should be treated as a toy.\n\n## Installation\n\n```sh\ncomposer require ssnepenthe/apheleia-cli\n```\n\n## Usage\n\nI think this is best explained through examples, so let's demonstrate some different ways we might implement the [`example hello` command from the WP-CLI handbook commands cookbook](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/#annotating-with-phpdoc).\n\nThe preferred approach is to create self-contained command classes.\n\nExtend the `Command` class using the `configure` method to define the command signature and the `handle` method to define the command logic to be executed when the command is called:\n\n```php\nuse ApheleiaCli\\Argument;\nuse ApheleiaCli\\Command;\nuse ApheleiaCli\\Option;\nuse WP_CLI;\n\nclass HelloCommand extends Command\n{\n    public function configure(): void\n    {\n        $this-\u003esetName('example hello')\n            -\u003esetDescription('Prints a greeting.')\n            -\u003eaddArgument(\n                (new Argument('name'))\n                    -\u003esetDescription('The name of the person to greet.')\n            )\n            -\u003eaddOption(\n                (new Option('type'))\n                    -\u003esetDescription('Whether or not to greet the person with success or error.')\n                    -\u003esetDefault('success')\n                    -\u003esetOptions('success', 'error')\n            )\n            -\u003esetUsage(\"## EXAMPLES\\n\\n\\twp example hello newman\")\n            -\u003esetWhen('after_wp_load');\n    }\n\n    public function handle($args, $assocArgs)\n    {\n        [$name] = $args;\n\n        $type = $assocArgs['type'];\n        WP_CLI::$type(\"Hello, $name!\");\n    }\n}\n```\n\nCommands are registered using the `CommandRegistry`.\n\n```php\nuse ApheleiaCli\\CommandRegistry;\n\n$registry = new CommandRegistry();\n\n$registry-\u003eadd(new HelloCommand());\n\n$registry-\u003einitialize();\n```\n\nThere is a significant difference between the command we have created and the original version: WP-CLI does not have any description text to display for the parent `example` command when you run `wp help example`.\n\nThere are a couple of different approaches we can take to fix this.\n\nThe first is to register a dedicated namespace alongside our `HelloCommand`:\n\n```php\n$registry-\u003enamespace('example', 'Implements example command.');\n$registry-\u003eadd(new HelloCommand());\n```\n\nThe second is to take advantage of command groups.\n\nFirst we need to remove the parent command portion of our command name:\n\n```php\nclass HelloCommand extends Command\n{\n    public function configure(): void\n    {\n        $this-\u003esetName('hello')\n            // etc...\n            ;\n    }\n\n    // ...\n}\n```\n\nAnd then we use the `group` method on our registry. The callback provided to the `group` method will receive a registry instance that has been scoped such that any commands added within the callback will automatically be registered as children of the `example` command:\n\n```php\n$registry-\u003egroup('example', 'Implements example command.', function (CommandRegistry $registry) {\n    $registry-\u003eadd(new HelloCommand());\n});\n```\n\nIt is also possible to define a command without extending the `Command` class:\n\n```php\n$registry-\u003eadd(\n    (new Command())\n        -\u003esetName('hello')\n        -\u003esetDescription('Prints a greeting.')\n        -\u003eaddArgument(\n            (new Argument('name'))\n                -\u003esetDescription('The name of the person to greet.')\n        )\n        -\u003eaddOption(\n            (new Option('type'))\n                -\u003esetDescription('Whether or not to greet the person with success or error.')\n                -\u003esetDefault('success')\n                -\u003esetOptions('success', 'error')\n        )\n        -\u003esetUsage(\"## EXAMPLES\\n\\n\\twp example hello newman\")\n        -\u003esetWhen('after_wp_load')\n        -\u003esetHandler(function ($args, $assocArgs) {\n            [$name] = $args;\n\n            $type = $assocArgs['type'];\n            WP_CLI::$type(\"Hello, $name!\");\n        })\n);\n```\n\n## Advanced Usage\n\nBy default, command handlers should be written more-or-less the same as they would if you were working directly with WP-CLI. That is to say they should always expect to receive a list of command arguments as the first parameter and an associative array of command options as the second:\n\n```php\n$command-\u003esetHandler(function (array $args, array $assocArgs) {\n    // ...\n});\n```\n\nHowever, commands can modify handler signatures by overriding their `handlerInvokerClass` property.\n\nThis package only ships with one alternative handler invoker: the `PhpDiHandlerInvoker`. It uses the [`php-di/invoker`](https://github.com/php-di/invoker) package to call command handlers.\n\nBefore it can be used, you must install `php-di/invoker`:\n\n```sh\ncomposer require php-di/invoker\n```\n\nThen set the handler invoker on your command (or a base command from which all of your commands extend):\n\n```php\nuse ApheleiaCli\\Invoker\\PhpDiHandlerInvoker;\n\nclass HelloCommand extends Command\n{\n    protected $handlerInvokerClass = PhpDiHandlerInvoker::class;\n\n    // ...\n}\n```\n\nWith this in place, command handlers can now ask for command parameters by name:\n\n```php\nclass HelloCommand extends Command\n{\n    // ...\n\n    public function handle($name, $type)\n    {\n        WP_CLI::$type(\"Hello, $name!\");\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssnepenthe%2Fapheleia-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssnepenthe%2Fapheleia-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssnepenthe%2Fapheleia-cli/lists"}