Skip to content

Finetuned/modx-cli

Repository files navigation

MODX CLI

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 modx/cli

Manual Installation

  1. Clone the repository:
git clone https://github.com/finetuned/modx-cli.git
cd modx-cli
  1. Install dependencies:
composer install
  1. Make the CLI executable:
chmod +x bin/modx
  1. 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 version
  • system:info - Get general system information
  • system:clearcache - Clear the MODX cache
  • resource:getlist - Get a list of resources
  • resource:create - Create a MODX resource
  • resource:update - Update a MODX resource
  • user:getlist - Get a list of users
  • template:getlist - Get a list of templates
  • And many more

To see all available commands, run:

modx list

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:getlist

Get a list of resources with filters:

modx resource:getlist --parent=1 --context=web --published=1

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.

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

About

Command Line Interface for MODX

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published