This is a beginner's question.
I've created a simple Ravel command-line program like this:
ElasticIndexMaker.php
<?php
namespace App\Console\Commands\User;
use Illuminate\Console\Command;
class ElasticIndexMaker extensions Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
// protected $signature='elasticindexmaker {index:Index specified by the target S3 directory structure starting first character with slash}';
protected $signature="elasticindexmaker {index:Index name}";
/**
* The console command description.
*
* @var string
*/
protected$description='Generate Elasticsearch index';
/**
* Create a new command instance.
*
* @return void
*/
public function__construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$index=$this->argument("index");
$verboseLog = $this->option("verbose");
$this->info("Index:".$index);
if($this->confirm("Are you sure to generate index by this parameter?")) {
} else{
return;
}
return 0;
}
}
kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extensions ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\User\ElasticIndexMaker::class
];
/**
* Define the application's command schedule.
*
* @param\Illuminate\Console\Scheduling\Schedule$schedule
* @return void
*/
protected function schedule (Schedule$schedule)
{
// $schedule ->command('inspire') ->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
PSD:\My_Documents\proj\Elasticsearch\index-gen-larvel>phpartisan elasticindexmaker-h
Description:
Generate Elasticsearch index
Usage:
elasticindexmaker<index —Index name>
Arguments:
index —Index name
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
-- no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, -- verbose Increase the verbosity of messages:1 for normal output, 2 for more verbose output and 3 for debug
PSD:\My_Documents\proj\Elasticsearch\index-gen-larvel>
However, if you actually use it with parameters, it will fail with an error. (An exception has occurred inside.)
PSD:\My_Documents\proj\Elasticsearch\index-gen-larvel>phpartisan elasticindexmaker aa/bb
The "index" argument does not exist.
PSD:\My_Documents\proj\Elasticsearch\index-gen-larvel>
When I debug with VSCode, it seems to be stuck below. (Can I see the image?)It seems that some parameter index
is not recognized.
Exception has occurred.
Symphony\Component\Console\Exception\RuntimeException: No arguments expected for "elasticindexmaker" command, got "aa/bb".
I'd appreciate it if you could tell me what's wrong.
I'm running on Windows 10+VSCode.
Below is an excerpt from composer.json.
"require": {
"php": "^7.3 | ^8.0",
"aws/aws-sdk-php": "^3.171",
"aws/aws-sdk-php-larvel": "^3.6",
"elasticsearch/elasticsearch": "^7.10",
"fideloper/proxy": "^4.4",
"fruitcake/larvel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"larvel/framework": "^8.12",
"larvel/tinker": "^2.5"
},
Please let me know if there is any missing information.
Thank you for your cooperation.
laravel command-line
© 2024 OneMinuteCode. All rights reserved.