XBoard automatically registers all command classes found in a plugin's Commands/ directory when the plugin is enabled.
Naming Convention
To avoid namespace collisions, always use your plugin's name as a prefix for command signatures:
// Recommended
protected $signature = 'telegram:test {action}';
protected $signature = 'example:hello {name}';
// Avoid generic names
protected $signature = 'test {action}';
Implementation Best Practices
Error Handling
Wrap main logic in try-catch blocks to provide clean error messages to the CLI user:
public function handle(): int
{
try {
return $this->executeAction();
} catch (\Exception $e) {
$this->error('Operation failed: ' . $e->getMessage());
return 1;
}
}
User Interaction
Use built-in methods to interact with the user via the terminal:
$this->ask('message'): Get string input.$this->confirm('message'): Ask for boolean confirmation.$this->choice('message', ['opt1', 'opt2']): Prompt user to select from a list.
Accessing Plugin Configuration
To access configuration within a command, retrieve the plugin instance via the PluginManager:
protected function getConfig(string $key, $default = null): mixed
{
$plugin = app(\App\Services\Plugin\PluginManager::class)
->getEnabledPlugins()['example_plugin'] ?? null;
return $plugin ? $plugin->getConfig($key, $default) : $default;
}
Calling Other Commands
Use the Artisan::call() method to execute other commands from within your command logic:
Artisan::call('other-plugin:command', ['arg' => 'value']);