Installation:
composer require atlas/cli --dev
require-dev in composer.json to avoid production bloat.Publish Config (if needed):
php artisan vendor:publish --provider="Atlas\Cli\CliServiceProvider"
config/atlas-cli.php for default settings (e.g., API endpoints, auth tokens).First Use Case: Run a basic Atlas command (e.g., list projects):
php artisan atlas:projects
.env (e.g., ATLAS_API_TOKEN=your_token_here).atlas:projects, atlas:deploy).Atlas\Cli\CliServiceProvider for binding/boot logic.src/Commands/ for available actions (e.g., ProjectsCommand, DeployCommand).Authentication Workflow:
.env (e.g., ATLAS_API_TOKEN).Atlas\Cli\Services\AuthService to validate tokens before commands run.$auth = app(AuthService::class);
if (!$auth->isAuthenticated()) {
throw new \RuntimeException("Authentication required.");
}
Command Integration:
Atlas\Cli\Commands\BaseCommand) for custom logic.atlas:custom-action command:
namespace App\Console\Commands;
use Atlas\Cli\Commands\BaseCommand;
class CustomAtlasCommand extends BaseCommand {
protected $signature = 'atlas:custom-action {argument}';
protected $description = 'Custom Atlas CLI action';
public function handle() {
$this->info("Running custom action for: {$this->argument}");
// Use Atlas\Cli\Services\AtlasService for API calls
}
}
App\Console\Kernel.php:
protected $commands = [
Commands\CustomAtlasCommand::class,
];
API Interaction:
Atlas\Cli\Services\AtlasService to wrap API calls (e.g., getProjects(), deploy()).$projects = app(AtlasService::class)->getProjects();
$this->table(array_keys($projects[0]), $projects);
Event-Driven Extensions:
atlas.deploy.started) via Laravel’s event system.EventServiceProvider:
protected $listen = [
'atlas.deploy.started' => [DeployLogger::class, 'log'],
];
package.json scripts for CI/CD (e.g., npm run deploy triggers php artisan atlas:deploy).app/Console/Kernel.php:
$schedule->command('atlas:check-updates')->daily();
AtlasService in PHPUnit:
$this->app->instance(AtlasService::class, Mockery::mock(AtlasService::class));
Authentication Caching:
refreshToken() method in AuthService if needed.if ($auth->isTokenExpired()) {
$auth->refreshToken();
}
Rate Limiting:
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient($httpClient, [
'max_retries' => 3,
'delay_factor' => 2,
]);
Command Output:
info()/error() with raw API responses. Use table() or json() for structured output:
$this->table(['ID', 'Name'], $projects);
Deprecated Methods:
changelog.md for removed features (e.g., AtlasService::oldMethod()).Enable Verbose Logging:
Set ATLAS_DEBUG=true in .env to log API requests/responses.
[Atlas] GET /api/projects | Status: 200 | Response: {"data": [...]}
Common Errors:
ATLAS_API_TOKEN in .env.try {
$response = $atlasService->deploy();
} catch (\Atlas\Cli\Exceptions\AtlasException $e) {
$this->error($e->getMessage());
}
API Response Parsing:
AtlasService::getPaginatedResults():
$projects = $atlasService->getPaginatedResults('/projects', ['limit' => 50]);
Custom API Endpoints:
Extend AtlasService to add methods for non-standard endpoints:
namespace App\Services;
use Atlas\Cli\Services\AtlasService;
class CustomAtlasService extends AtlasService {
public function getCustomData() {
return $this->get('/custom-endpoint');
}
}
Bind in AppServiceProvider:
$this->app->bind(CustomAtlasService::class, function ($app) {
return new CustomAtlasService($app->make(AtlasService::class));
});
Command Pre/Post Hooks:
Use Laravel’s registering and registered events for commands:
// In AppServiceProvider
Atlas\Cli\Commands\BaseCommand::registering(function ($command) {
$command->setLaravel($this->app);
});
Configuration Overrides:
Override config/atlas-cli.php for environment-specific settings (e.g., staging vs. production endpoints):
'endpoints' => [
'api' => env('ATLAS_API_URL', 'https://api.atlas.example.com'),
],
Testing Helpers: Create a trait for testing Atlas commands:
trait TestsAtlasCommands {
protected function callAtlasCommand($command, array $args = []) {
return $this->artisan("atlas:{$command}", $args)
->expectsQuestion('Confirm?', 'yes')
->assertExitCode(0);
}
}
How can I help you explore Laravel packages today?