PHPackages                             stellarwp/foundation-wpcli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. stellarwp/foundation-wpcli

ActiveLibrary[CLI &amp; Console](/categories/cli)

stellarwp/foundation-wpcli
==========================

Foundation WP-CLI helpers.

1.2.0(1w ago)00GPL-2.0-or-laterPHPPHP &gt;=8.3

Since Jun 2Pushed todayCompare

[ Source](https://github.com/stellarwp/foundation-wpcli)[ Packagist](https://packagist.org/packages/stellarwp/foundation-wpcli)[ RSS](/packages/stellarwp-foundation-wpcli/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

Foundation WP-CLI
=================

[](#foundation-wp-cli)

Warning

**This is a read-only repository!** For pull requests or issues, see [stellarwp/foundation](https://github.com/stellarwp/foundation).

Foundation helpers for building WP-CLI commands with the Foundation container.

Installation
------------

[](#installation)

```
composer require stellarwp/foundation-wpcli
```

WP-CLI is expected to provide the `WP_CLI` and `WP_CLI_Command` runtime classes. This package includes `wp-cli/wp-cli` as a development dependency for tests and static analysis, but applications normally do not need to install it separately when running inside WP-CLI.

Install `stellarwp/foundation-wpcli` as a normal dependency when the plugin ships WP-CLI commands. Install `stellarwp/foundation-cli` separately with `composer require --dev stellarwp/foundation-cli` only when developers need generators such as `make:wpcli-command`.

Commands
--------

[](#commands)

Extend `StellarWP\Foundation\WPCli\Command` for commands that should receive the Foundation container.

Generating Commands
-------------------

[](#generating-commands)

If the project also installs `stellarwp/foundation-cli` as a development dependency, scaffold a WP-CLI command class in a consuming WordPress project:

```
vendor/bin/foundation make:wpcli-command Sync_Products_Command
```

If the consuming project has a Composer script named `foundation` that points to the installed Foundation binary, it can also run `composer run foundation -- make:wpcli-command Sync_Products_Command`.

The generator reads the project's `autoload.psr-4` namespaces from `composer.json` and writes a Snake\_Case command class under `Cli/Commands` inside the default PSR-4 root. When `--namespace` is passed, the output path is resolved from the matching PSR-4 root unless `--path` is also passed.

For example, a project with this Composer autoload entry:

```
{
    "autoload": {
        "psr-4": {
            "Acme\\Plugin\\": "src"
        }
    }
}
```

will generate:

```
src/Cli/Commands/Sync_Products_Command.php

```

with namespace:

```
Acme\Plugin\Cli\Commands
```

The generated class extends `StellarWP\Foundation\WPCli\Command` and includes example positional, associative, and flag arguments using constants.

When generated through `foundation-cli`, projects using Strauss with `extra.strauss.namespace_prefix` receive prefixed Foundation imports automatically.

Available options:

```
vendor/bin/foundation make:wpcli-command Sync_Products_Command --namespace="Acme\\Plugin\\Cli" --path=src/Cli --subcommand=sync-products --description="Sync products." --force
```

Project stub overrides live under:

```
foundation/stubs/wpcli/command.stub

```

When present, the override is used instead of the default stub from the `foundation-wpcli` package.

Override stubs should use the same context-aware placeholders as the default stub when writing PHP literals. For example, use `{{ description_php }}` and `{{ subcommand_php }}` for values returned from PHP methods, and `{{ foundation_wpcli_command }}` for the Foundation command import so Strauss-prefixed projects keep working.

```
