Foundation CLI
Foundation CLI is development tooling for generating project code. It reads the consuming project’s Composer configuration, follows WordPress naming and formatting conventions, and uses stubs owned by the runtime package that defines each generated API.
Installation
Section titled “Installation”Install the CLI as a development dependency in a consuming project:
List its available commands:
Do not register StellarWP\Foundation\Cli\CliProvider in the WordPress application’s provider list. It boots the Symfony Console application for the foundation executable and is unrelated to WordPress request bootstrap.
Add a Composer script
Section titled “Add a Composer script”The binary can be exposed through a project script in composer.json:
Pass command arguments after --:
Generate project code
Section titled “Generate project code”Generate a WP-CLI command
Section titled “Generate a WP-CLI command”The generated class extends Foundation’s WP-CLI command base and demonstrates positional arguments, associative options, and flags. A command shipped by the plugin requires the runtime package:
Generate a database feature
Section titled “Generate a database feature”Generate the application provider first so later generators can register the table and migration automatically:
Generated database classes require the runtime package:
Database table and migration generators refuse to overwrite existing files. Edit an unapplied migration directly, or create a new migration after the existing one has been deployed.
Inspect command options
Section titled “Inspect command options”Use Symfony Console’s built-in help for supported names, paths, namespaces, and feature-specific options:
The generators use the first autoload.psr-4 entry in the project’s composer.json to determine the default namespace and source path. Explicit --namespace and --path options override those defaults.
Customize generation
Section titled “Customize generation”Override package stubs
Section titled “Override package stubs”Place project-specific stubs under foundation/stubs/ using the same feature path as the package default:
Copy the package’s default stub before customizing it so required placeholders remain available. Local scaffolding assets that should not ship in a production zip should be excluded in the consuming project’s .gitattributes.
Generate Strauss-compatible imports
Section titled “Generate Strauss-compatible imports”When the consuming project’s composer.json defines extra.strauss.namespace_prefix, generators apply that prefix to Foundation imports. For example, a configured YourPlugin\\ prefix changes:
to:
This keeps generated classes compatible when Strauss prefixes dependencies without updating project call sites. Handwritten imports remain the application’s responsibility.
Build a project-specific CLI
Section titled “Build a project-specific CLI”The installed vendor/bin/foundation executable contains Foundation’s commands. A project that needs its own Symfony Console commands can create a separate executable using StellarWP\Foundation\Cli\Application.
In src/Cli/Cache_Clear_Command.php:
In src/Cli/Command_Provider.php:
Then create the project’s executable, for example bin/your-plugin:
This small example has no application dependencies. When commands need services, construct the command provider through the project’s container instead of creating dependencies inside command classes.
Foundation monorepo maintenance
Section titled “Foundation monorepo maintenance”Preview the repository actions without changing GitHub:
Pass --apply only after reviewing the generated actions:
The command can create src/<Package> scaffolding, asks for the Composer package name, and runs composer monorepo merge after local package creation.