Evet, Laravel'in komut imza (signature) yapısı, tek tireli kısa argümanlar (alias) tanımlamanıza olanak tanır. Mevcut imzanızı şu şekilde güncelleyebilirsiniz:
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
class YourCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:cari-project-data
{--task= : Task to perform (e.g., cleanup_inactive_tkn_accounts)}
{c|cari-csv-path= : Path to the cari CSV file}
{p|proje-csv-path= : Path to the proje CSV file}
{--dry-run : Run without making changes (dry run)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Imports CARI and PROJE project data';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$cariPath = $this->option('cari-csv-path');
$projePath = $this->option('proje-csv-path');
$task = $this->option('task');
$dryRun = $this->option('dry-run');
$this->info("Task: " . ($task ?? 'N/A'));
$this->info("CARI Path: " . ($cariPath ?? 'Not specified'));
$this->info("PROJE Path: " . ($projePath ?? 'Not specified'));
$this->info("Dry Run: " . ($dryRun ? 'Yes' : 'No'));
// Komutunuzun iş mantığını buraya ekleyin
// Örneğin:
// if ($cariPath) {
// // cari CSV dosyasını işle
// }
// if ($projePath) {
// // proje CSV dosyasını işle
// }
return 0; // Başarılı çıkış
}
}
Açıklama:
{c|cari-csv-path=}: Bu satır, hem -c hem de --cari-csv-path argümanlarının kabul edileceğini belirtir. = işareti, bu seçeneğin bir değer alması gerektiğini gösterir (örneğin, -c path/to/file.csv veya --cari-csv-path=path/to/file.csv).
{p|proje-csv-path=}: Benzer şekilde, bu satır da hem -p hem de --proje-csv-path argümanlarının kabul edileceğini ve bir değer alması gerektiğini belirtir.
Artık komutunuzu şu şekillerde çalıştırabilirsiniz:
php artisan import:cari-project-data -c path/to/cari.csv -p path/to/proje.csv
php artisan import:cari-project-data --cari-csv-path=path/to/cari.csv --proje-csv-path=path/to/proje.csv
php artisan import:cari-project-data -c path/to/cari.csv --proje-csv-path=path/to/proje.csv
Kısa ve uzun argümanlar arasında geçiş yapabilirsiniz. Laravel, handle metodu içinde option('cari-csv-path') veya option('c') kullanarak doğru değeri almanızı sağlar (her ikisi de aynı değeri verecektir).