Operations

Console (CLI)

The lunar script is the framework’s console. It bootstraps .env, config and the log driver before running a command — so helpers are available inside your commands.

Running commands

php lunar key:generate

The CLI bootstraps .env, config and the log driver before running a command, so env(), config() and Log::* are all available inside your commands. Routes are not loaded — the console stops right before HTTP dispatch.

Built-in commands

CommandDescription
key:generateGenerates a new Defuse ASCII-safe APP_KEY and writes it to .env.

Adding a command

Register command classes in routes/console.php, mapping name → class:

<?php

use System\Cli\Commands\KeyGenerate;
use App\Commands\MakeUser;

return [
    "key:generate" => KeyGenerate::class,
    "make:user" => MakeUser::class,
];

Create the command class extending System\Cli\Command:

<?php

namespace App\Commands;

use System\Cli\Command;

class MakeUser extends Command {
    public function main(): void {
        $name = $this->arg("name");                    // --name=foo
        $force = $this->flag("force");                 // --force
        $positional = $this->args()[0] ?? null;        // bare positional argument
        $answer = $this->ask("User email");            // prompt on stdin

        $this->info("Creating user...");
        // ... work ...
        $this->success("User created");
    }
}

Run it:

php lunar make:user --name=alice --force

Command helpers

MethodDescription
arg($key, $default)Value of a --key=value argument.
has($key)Whether a key was passed.
flag($key)True only if --key was passed as a bare flag.
args()All parsed arguments.
ask($question)Prompt and read a line from STDIN.
success($msg) / error($msg) / info($msg)ANSI-colored output (green / red / blue).
$this->basePathThe project root path (injected).

Argument parsing supports --key=value, bare --flag (→ true), and positional strings (→ numeric indexes).

Error handling

The console dispatcher reports unknown commands and bad arguments in ANSI red; main() has no return value — print your result and you’re done.

Part of the Lunaris documentation · Source on Codeberg · MIT License