finetuned / modx-cli
MODX 3 CLI
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/finetuned/modx-cli
Requires
- php: >=7.4
- symfony/console: ^5.4
- symfony/finder: ^5.4
- symfony/process: ^5.4
- symfony/yaml: ^5.4
Requires (Dev)
- modx/revolution: ^3.1
- phpspec/prophecy: ^1.20
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.12
This package is auto-updated.
Last update: 2025-10-25 14:57:48 UTC
README
A command-line interface for MODX 3, built with Symfony Console.
Requirements
- PHP 7.4 or higher
- MODX 3.0.0 or higher
Installation
Via Composer
composer global require finetuned/modx-cli
Manual Installation
- 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/modx
Usage
Basic Usage
modx [command] [options]
Available Commands
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 list
Command Features
Update 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.
Examples
Display the CLI version:
modx version
Get system information:
modx system:info
Clear the MODX cache:
modx system:clearcache
Get a list of resources:
modx resource:list
Get a list of resources with filters and pagination:
modx resource:list --parent=1 --context=web --published=1 --limit=20 --start=0
Update Command Examples
Update 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 Command Examples
Create a new resource with specific settings:
modx resource:create "My New Page" --parent=1 --template=2 --published=1
Create a new chunk:
modx chunk:create "MyChunk" --description="A new chunk" --snippet="<p>Chunk content</p>"
List Command Examples with Pagination
Get the first 10 packages:
modx package:list --limit=10 --start=0
Get the next 10 packages:
modx package:list --limit=10 --start=10
JSON Output Examples
Get resource data in JSON format:
modx resource:get 123 --json
Get a list of templates in JSON format:
modx template:list --json
Working with Multiple MODX Instances
Most 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 mysite
You can also specify a MODX instance to run a command on:
modx --site=mysite system:info
SSH and Aliases
MODX CLI supports running commands on remote servers via SSH and using aliases to simplify working with multiple MODX installations.
SSH Mode
Run commands on a remote server:
modx --ssh=user@example.com:/path/to/modx system:info
Aliases
Define 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/modx
Use aliases to run commands:
modx @prod system:info
Define alias groups to run commands on multiple servers:
@all: - @prod - @staging
modx @all system:clear-cache
For more information, see SSH and Aliases Documentation.
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
Bash Completion
To enable bash completion, add the following to your .bashrc or .bash_profile:
source /path/to/modx_completion.sh
Building the PHAR
To build the PHAR file:
composer install --no-dev box compile
This will create a modx-cli.phar file in the root directory.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT