CLI · Winter Console

The script command

script (aliased sc) runs your console classes: it resolves a name in dot notation into a class, checks that it extends Cmd/CmdCustom, and runs it. That is how one-off scripts and project chores are started.

Alias scRun call sc dot.ClassBase Cmd / CmdCustom

What script is and why

script is the command that runs user console classes.

The problem. Not every task deserves a first-class command in call help: a one-off import, a seeder, a maintenance script. You need a way to run any class from the project as a console command.

The solution. Write a class on top of CmdCustom and run it with call sc <path.Class> — with the same DI and argument parsing the built-in commands have. That is what this page is about.

Subcommands

Subcommand Purpose
list Show every Cmd/CmdCustom class, labelled by type
<dot.notation.Class> [args] [-flags] [--options] Run a class
bash
php call sc list
php call sc app.console.SeedUsers
php call sc app.console.SeedUsers --count=100 --reset

How the name is resolved

Dot notation turns into an FQCN: ./, each segment through ucfirst, then /\. Arguments, flags and options after the class name are passed to its ::script(). If the class is not found or does not extend Cmd/CmdCustom, the command warns you and shows the FQCN it computed.

A command of your own

The scaffold for a one-off command is make’s -n flag:

bash
php call make -n .SeedUsers   # → main/SeedUsers.php (CmdCustom)
main/SeedUsers.php
use Flytachi\Winter\Console\Stereotype\CmdCustom;

class SeedUsers extends CmdCustom
{
  #[Autowired] private UserRepository $repo;

  public function handle(): void
  {
      $count = (int) ($this->args['options']['count'] ?? 10);
      // ... seeding
      self::printSuccess("Seeded {$count} users");
  }
}

Cmd versus CmdCustom

CmdCustom does not appear in call help and is only started through call sc. If the command should be first-class (listed in help, started as call <name>), extend Cmd. The differences are in the console overview.

Next