Osumi Framework
es en eu v9.8.0 GitHub

CLI (Command Line Interface)

Osumi Framework provides a powerful command-line interface to automate development tasks, manage the database, and run custom scripts. The entry point for all CLI commands is the of file located in the root of your project.


Usage

Commands are executed using PHP from the terminal:

php of <option> [arguments]

If the file is executed without any arguments, the list of available options are shown (both Framework options and user created ones).

Core Commands

The framework includes several built-in tasks:


Custom Tasks

You can extend the CLI by creating your own tasks. Any class placed in src/Task/ that extends OTask will automatically appear as an available option in the of command.

Creating a Task

A task requires two main elements:

  1. __toString(): Returns a brief description of the task (displayed in the help menu).
  2. run(array $options): The logic to be executed.

Example: AddUserTask.php

<?php declare(strict_types=1);

namespace Osumi\OsumiFramework\App\Task;

use Osumi\OsumiFramework\Core\OTask;
use Osumi\OsumiFramework\App\Model\User;

class AddUserTask extends OTask {
  public function __toString() {
    return "addUser: Task to create new users";
  }

  public function run(array $options=[]): void {
    $name = $options['name'] ?? $options[0] ?? null;

    if (is_null($name)) {
      echo "Error: Name is required.\n";
      return;
    }

    $u = new User();
    $u->name = $name;
    $u->save();

    echo "User " . $name . " created successfully.\n";
  }
}


Handling Arguments

The run method receives an $options array that supports two styles of input:

1. Positional Arguments

Passed directly after the command name.

php of addUser "John Doe"
# $options = [0 => "John Doe"]

2. Named Parameters

Using the --key value syntax. This results in an associative array.

php of addUser --name "John Doe"
# $options = ["name" => "John Doe"]

Note on $options$: The $options parameter is always an array, DTOs can't be used on Tasks.


Task Features

Classes extending OTask have access to several built-in utilities:


Best Practices