Skip to content

Command-Line Interface

This page provides an overview of the Mago command-line interface (CLI), including global options and subcommands.

Usage Pattern

Mago follows a standard [GLOBAL OPTIONS] <SUBCOMMAND> pattern. Global options must be specified before the subcommand.

sh
# Correct: Global option before subcommand
mago --colors=never lint

# Incorrect: Global option after subcommand
mago lint --colors=never

Global Options

These options can be used with the main mago command and any of its subcommands. They control the overall execution environment and configuration.

Flag, Alias(es)Description
--workspace <PATH>Sets the path to the workspace directory, which is the root of your project. Defaults to the current directory.
--config <PATH>Specifies the path to the configuration file. If not provided, Mago searches for mago.toml in the workspace.
--php-version <VERSION>Overrides the PHP version (e.g., 8.2) specified in the configuration file.
--threads <NUMBER>Overrides the number of threads Mago will use. Defaults to the number of available logical CPUs.
--allow-unsupported-php-versionAllows Mago to run against a PHP version that is not officially supported. Use with caution.
--no-color, --no-colorsDisables all color in the output. This option has been deprecated. Use --colors never instead.
--colors <WHEN>Controls when to use colors in the output. Options: always, never, auto (default).
-h, --helpPrint help information.
-V, --versionPrint version information.

Subcommands

Mago is organized into several tools and utility commands, each accessed via a subcommand.

Tools

CommandDescription
mago analyzeAnalyzes PHP code for type-safety and other issues.
mago astInspects the Abstract Syntax Tree of a PHP file.
mago formatFormats PHP code.
mago guardEnforces architectural rules and boundaries.
mago lintLints PHP code for style, correctness, and best practices.

Utility Commands

CommandDescription
mago configDisplays the final, merged configuration Mago is using.
mago list-filesDisplays a list of the files scanned by Mago.
mago generate-completionsGenerate shell completions for Mago.
mago initInitializes a new Mago configuration file.
mago self-updateUpdates Mago to the latest version.