CLI

The phlat command line tool for scaffolding, maintenance and the registry.

On this page

Usage

The tool ships in phlat/addons/cli/, one copy per project, versioned with core. It finds the project root by walking up from the current directory to a vendor/autoload.php beside a site/ folder, so it works from anywhere in the project.

composer exec phlat -- <command> [args] [--flags]
php phlat/addons/cli/phlat <command>

phlat help
phlat help make
phlat make:page --help

Built-in commands

Namespace Commands
addons install, mount, reset, uninstall, update
backup create, restore
cache clear
clockwork clear, prune, status
collection prune, reindex
db backup, optimize, vacuum
files rebuild
health check, disk
make field, page, view
page access, delete, field, list, move, publish
registry check, rebuild
user create, delete, list, password, role
uuid generate, regenerate

Namespaces

Core and site/commands/ share one unprefixed namespace. A site command with the same name as a built-in is a hard error, and phlat refuses to run until it is renamed. Every other addon with a commands/ folder is pinned under its own alias: phlat/addons/git/commands/log.php runs as @git:log.

Writing a command

A command is a plain PHP file. $app and $args are in scope, and the file path is the command name: commands/make/page.php is make:page. Lead with a docblock (its first line is the summary in listings) and bail out on --help:

<?php

declare(strict_types=1);

/** @var \Phlat\App $app */
/** @var array $args */

/**
 * One-line summary of what this command does.
 *
 * Usage: phlat namespace:command [arg] [--flag=]
 */

use Phlat\Toolkit\Cli;

if (Cli::wantsHelp($args)) {
    Cli::usage(__FILE__);
}

[$positional, $flags] = Cli::args($args);

--flag is true, --name=value is the value, and everything else is positional. Use Phlat\Toolkit\Cli for all output (Cli::info(), success(), warning(), error(), table()). A new namespace folder appears in phlat help with no extra registration.