Commands

Making a Command

To make your own galaxy CLI command use the galaxy command make:command. Galaxy commands use the Symfony Console Package. Lets make a command named app:test.

php galaxy make:command Test app:test

This will output,

Command created: Test
Configure Command Test: Add your command to config/galaxy.php

You can now find your new command at app/Commands/Test.php. We will take a look at it next, but first add the command to the galaxy.php configuration file.

'commands' => [
    \App\Commands\Test::class
]

Now run php galaxy list and check for:

app
  app:test         Short description here

Now run the command:

 php galaxy app:test

This will output,

Executed!

You are now ready to start building your command.

Coding Commands

Here is the Test command class we just created. If you want to make your commands without the galaxy CLI this can serve as a working template.

<?php
namespace App\Commands;

use \TypeRocket\Console\Command;

class Test extends Command
{

    protected $command = [
        'app:test',
        'Short description here',
        'Longer help text goes here.',
    ];

    protected function config()
    {
        // If you want to accept arguments
        // $this->addArgument('arg', self::REQUIRED, 'Description');
    }

    public function exec()
    {
        // When command executes
        $this->success('Execute!');
    }
}