1
DRY-RUN-PATTERN
Jonathan Miller edited this page 2026-06-09 16:55:04 +00:00

Dry Run Pattern

The --dry-run flag pattern used across all CLI tools.

Usage

php bin/moko bulk:push-workflow --workflow ci-joomla.yml --dry-run

When --dry-run is set, the tool reports what it would do without making changes.

Implementation

In CliBase

abstract class CliBase
{
    protected bool $dryRun = false;

    protected function parseArgs(): void
    {
        $this->dryRun = in_array('--dry-run', $this->args);
    }
}

In Tools

protected function run(): int
{
    foreach ($repos as $repo) {
        if ($this->dryRun) {
            $this->info("[DRY RUN] Would push workflow to {$repo}");
            continue;
        }
        $this->pushWorkflow($repo);
    }
    return 0;
}

Rules

  • All destructive operations MUST check $this->dryRun
  • Dry run output prefixed with [DRY RUN]
  • Dry run must exercise the same code paths (validation, file reading) without writes
  • Bulk operations default to dry-run when --force is not set