pomm-project/cli
Command-line tools for Pomm, the PostgreSQL ORM for PHP. Provides a CLI to help generate and manage models, schemas and project scaffolding, automate database-related tasks, and speed up development workflows from the terminal.
Installation
composer require pomm-project/cli
Add the service provider to config/app.php:
Pomm\Cli\CliServiceProvider::class,
First Command
Register a basic command in app/Console/Kernel.php:
use Pomm\Cli\Commands\BaseCommand;
protected $commands = [
\App\Console\Commands\MyCustomCommand::class,
];
Define a Command
Extend BaseCommand in app/Console/Commands/MyCustomCommand.php:
namespace App\Console\Commands;
use Pomm\Cli\Commands\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MyCustomCommand extends BaseCommand
{
protected function configure()
{
$this->setName('app:my-command')
->setDescription('A custom Pomm CLI command');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Hello from Pomm CLI!');
return 0;
}
}
Run It
php artisan app:my-command
Pomm\Cli\Commands\BaseCommand for built-in helpers (logging, input/output, etc.).InputInterface/OutputInterface for advanced CLI features.Input/Output Handling
Use Symfony’s InputInterface for arguments/options and OutputInterface for output:
$name = $input->getArgument('name');
$output->writeln("Processing: {$name}");
Logging
Inject Psr\Log\LoggerInterface via constructor (Pomm CLI supports dependency injection):
public function __construct(protected LoggerInterface $logger) {}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger->info('Command started');
}
Interactive Prompts
Use Symfony’s QuestionHelper for user input:
$helper = $this->getHelper('question');
$question = new Question('Confirm? (y/n) ', 'n');
$answer = $helper->ask($input, $output, $question);
Artisan Integration Call other Artisan commands from within a Pomm CLI command:
$this->call('migrate', [
'--force' => true,
]);
Event Listeners Dispatch events for post-execution hooks:
event(new \App\Events\CommandExecuted($this->getName()));
pomm-project/core for database interactions:
use PommProject\Pomm\Client;
public function __construct(protected Client $client) {}
Symfony\Component\Console\Tester\CommandTester for unit tests:
$command = new MyCustomCommand();
$commandTester = new CommandTester($command);
$commandTester->execute(['--option' => 'value']);
$this->assertEquals('Expected output', $commandTester->getDisplay());
.env or custom config files.Dependency Injection
$container->bind(LoggerInterface::class, function () {
return new Monolog\Logger('name');
});
Output Buffering
OutputInterface may buffer output. Force immediate display with:
$output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL
? $output->writeln($message)
: $output->write($message . PHP_EOL);
Error Handling
execute() will terminate the CLI. Use try-catch:
try {
// Risky operations
} catch (\Exception $e) {
$output->writeln('<error>Error: ' . $e->getMessage() . '</error>');
return 1;
}
Command Naming Conflicts
migrate). Prefix with app::
$this->setName('app:migrate-custom');
--verbose or -v for detailed logs.var_dump() or json_encode() for debugging:
$output->writeln(json_encode($input->getOptions(), JSON_PRETTY_PRINT));
php -dxdebug.start_with_xdebug=1 artisan app:my-command
Custom Helpers
Extend Symfony\Component\Console\Helper\HelperSet to add reusable logic:
$this->addHelper(new class extends Helper {
public function __invoke() { /* Custom logic */ }
});
Command Groups Organize commands into groups for better CLI navigation:
$this->setName('app:group:subcommand');
Progress Bars
Use Symfony’s ProgressBar for long-running tasks:
$progress = new ProgressBar($output, 100);
for ($i = 0; $i < 100; $i++) {
$progress->advance();
}
Color Schemes
Customize output colors via OutputInterface:
$output->writeln('<info>Info</info>');
$output->writeln('<comment>Comment</comment>');
Async Commands
For background tasks, use Laravel’s queues or Symfony’s Process component:
use Symfony\Component\Process\Process;
$process = new Process(['php', 'artisan', 'queue:work']);
$process->start();
How can I help you explore Laravel packages today?