A command-line interface for MODX 3, built with Symfony Console.
- PHP 8.0 or higher
- MODX 3.0.0 or higher
composer global require finetuned/modx-cli- Clone the repository:
git clone https://github.com/finetuned/modx-cli.git
cd modx-cli- Install dependencies:
composer install- Make the CLI executable:
chmod +x bin/modx- Create a symbolic link to make the CLI available globally:
sudo ln -s $(pwd)/bin/modx /usr/local/bin/modxmodx [command] [options]When a MODX instance is configured and set as default, many commands become available, including:
version- Display the CLI versionsystem:info- Get general system informationsystem:clearcache- Clear the MODX cacheresource:list- Get a list of resourcesresource:create- Create a MODX resourceresource:update- Update a MODX resource (supports partial updates)chunk:list- Get a list of chunkschunk:create- Create a MODX chunkchunk:update- Update a MODX chunk (supports partial updates)template:list- Get a list of templatestemplate:create- Create a MODX templatetemplate:update- Update a MODX template (supports partial updates)snippet:list- Get a list of snippetssnippet:create- Create a MODX snippetsnippet:update- Update a MODX snippet (supports partial updates)tv:list- Get a list of template variablestv:create- Create a MODX template variabletv:update- Update a MODX template variable (supports partial updates)user:list- Get a list of userspackage:list- Get a list of packages (supports pagination)crawl- Crawl resources to prime their caches- And many more
To see all available commands, run:
modx listUpdate Commands: All update commands now support partial updates - you only need to specify the ID and the fields you want to change. The CLI automatically fetches existing data to populate required fields.
List Commands: All list commands support pagination with --limit and --start options for navigating large datasets.
JSON Output: All commands support --json flag for machine-readable output.
Enhanced Logging: Built-in PSR-3 compliant logging system with file logging, automatic rotation, and verbosity controls.
The CLI includes a comprehensive logging system for better debugging and operational visibility:
# Control console output verbosity
modx command -v # verbose
modx command -vv # very verbose
modx command -vvv # debug
modx command --quiet # no output
# Write logs to a file
modx command --log-file=/var/log/modx-cli.log
# Set log level (filters which messages are logged)
modx command --log-level=debugAll commands extending BaseCmd have automatic access to logging:
$this->logInfo('Processing started');
$this->logDebug('Item {id} processed', ['id' => 123]);
$this->logError('Operation failed: {error}', ['error' => $e->getMessage()]);For complete documentation, see Enhanced Logging System.
MODX CLI features a powerful plugin system for extending functionality without modifying core code:
// Create a plugin by extending AbstractPlugin
class MyPlugin extends AbstractPlugin
{
public function getName(): string
{
return 'my-plugin';
}
public function getCommands(): array
{
return [MyCommand::class];
}
public function getHooks(): array
{
return [
'command.before' => [$this, 'onCommandBefore']
];
}
}Features:
- Automatic plugin discovery and loading
- Hook system for event-driven extensions
- Command registration
- Configuration management
- Enable/disable functionality
For complete documentation, see Plugin Architecture.
Enhanced output capabilities for long-running commands:
class MyCommand extends BaseCmd
{
use StreamingOutputTrait;
protected function process()
{
// Progress bars
$this->startProgress(100, 'Processing...');
$this->advanceProgress(10);
$this->finishProgress();
// Real-time streaming
$this->stream('Processing item...');
// Section-based output
$section = $this->createSection();
$section->write('Status: Running');
$section->overwrite('Status: Complete');
return 0;
}
}Features:
- Real-time streaming output
- Progress bars with custom formats
- Buffered and unbuffered modes
- Section-based output
- Event callbacks and statistics
For complete documentation, see Command Output Streaming.
Display the CLI version:
modx versionGet system information:
modx system:infoClear the MODX cache:
modx system:clearcacheGet a list of resources:
modx resource:listGet a list of resources with filters and pagination:
modx resource:list --parent=1 --context=web --published=1 --limit=20 --start=0Update only the title of a resource (partial update):
modx resource:update 123 --pagetitle="New Title"Update multiple fields of a chunk:
modx chunk:update 5 --description="Updated description" --snippet="<p>New content</p>"Update a template variable with new default value:
modx tv:update 10 --default_text="New default value" --description="Updated TV"Create a new resource with specific settings:
modx resource:create "My New Page" --parent=1 --template=2 --published=1Create a new chunk:
modx chunk:create "MyChunk" --description="A new chunk" --snippet="<p>Chunk content</p>"Get the first 10 packages:
modx package:list --limit=10 --start=0Get the next 10 packages:
modx package:list --limit=10 --start=10Get resource data in JSON format:
modx resource:get 123 --jsonGet a list of templates in JSON format:
modx template:list --jsonMost commands in the MODX CLI require a MODX instance to be available. To see all available commands, you need to configure at least one MODX instance and set it as the default.
To add a MODX instance:
modx config:add mysite --base_path=/path/to/modx/To set a MODX instance as the default:
modx config:set-default mysiteYou can also specify a MODX instance to run a command on:
modx --site=mysite system:infoMODX CLI supports running commands on remote servers via SSH and using aliases to simplify working with multiple MODX installations.
Run commands on a remote server:
modx --ssh=user@example.com:/path/to/modx system:infoDefine aliases in ~/.modx/config.yml or modx-cli.yml in your project directory:
@prod:
ssh: user@production-server.com:/path/to/modx
@staging:
ssh: user@staging-server.com:/path/to/modxUse aliases to run commands:
modx @prod system:infoDefine alias groups to run commands on multiple servers:
@all:
- @prod
- @stagingmodx @all system:clear-cacheFor more information, see SSH and Aliases Documentation.
- Update Commands - Detailed guide to the enhanced update functionality
- List Commands - Pagination and filtering for list commands
- SSH and Aliases - Remote command execution and aliases
- Internal API - Programmatic usage and extending the CLI
- Running Tests - Guide to running the test suite
- Debugging Setup - VS Code debugging configuration
- Code Style Guide - Coding standards and PHP_CodeSniffer setup
- Medium-Term Enhancements - Centralized error messages, field mappings, and metadata registry
- TODO Priority List - Prioritized list of technical debt items
- GitHub Issues to Create - Major initiative issue templates
- Type Declarations Progress - Tracking type hint implementation
To enable bash completion, add the following to your .bashrc or .bash_profile:
source /path/to/modx_completion.shTo build the PHAR file:
composer install --no-dev
box compileThis will create a modx-cli.phar file in the root directory.
This project follows PSR-12 coding standards. Check your code style:
# Check code style
composer cs:check
# Automatically fix code style issues
composer cs:fix# Run all tests
composer test
# Run unit tests only
composer test:unit
# Run integration tests only
composer test:integrationSee Running Tests for more details.
This project uses PHPStan for static analysis:
# Run static analysis
composer analyse
# Generate baseline for existing issues
composer analyse:baselineContributions are welcome! Please feel free to submit a Pull Request.
Before contributing, please:
- Read the Code Style Guide
- Ensure your code passes
composer cs:check - Add tests for new functionality
- Update documentation as needed
MIT