1
NEW-SCRIPTS
Jonathan Miller edited this page 2026-06-09 16:55:07 +00:00

Creating New CLI Tools

Guide to adding new commands to mokoplatform.

Steps

  1. Create script in cli/:

    touch cli/my_new_tool.php
    chmod +x cli/my_new_tool.php
    
  2. Extend CliBase (simple) or CliFramework (complex):

    <?php
    declare(strict_types=1);
    require_once __DIR__ . '/../lib/CliBase.php';
    
    class MyNewTool extends CliBase
    {
        protected string $description = 'What this tool does';
    
        protected function run(): int
        {
            $path = $this->getOption('path', '.');
            if ($this->dryRun) {
                $this->info('[DRY RUN] Would process: ' . $path);
                return 0;
            }
            // ... do work
            $this->success('Done');
            return 0;
        }
    }
    
    (new MyNewTool())->execute();
    
  3. Register in bin/moko command registry

  4. Add wrapper (optional) in wrappers/ for CI usage

  5. Add test in tests/

Conventions

  • Script filename: snake_case.php
  • Command name: group:action (e.g., build:joomla)
  • Always support --dry-run for destructive operations
  • Always support --verbose for debug output
  • Always support --path for target directory
  • Use $this->info(), $this->success(), $this->error() for output