Reputation: 18133
I have a simple symfony console application with following entry point
#!/usr/bin/env php
<?php
include __DIR__ . '/vendor/autoload.php';
use Rkmax\Application;
$app = new Application();
$app->run();
my Application class
class Application extends BaseApplication
{
public function __construct($name = 'myapp', $version = '0.1')
{
parent::__construct($name, $version);
$this->add(new Command\SingleCommand());
}
}
and my command
class SingleCommand extends Command
{
const KEYWORDS = 'keywords';
protected function configure()
{
$this
->setName("single")
->setDescription("Sample")
->addArgument(self::KEYWORDS, InputArgument::OPTIONAL, "Keywords for the search")
;
}
public function run(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}
}
i cant understand where is the problem always i get the error
[InvalidArgumentException]
The "keywords" argument does not exist.
Upvotes: 3
Views: 5489
Reputation: 643
You should probably override the execute method not run.
public function execute(InputInterface $input, OutputInterface $output)
{
$keywords = $input->getArgument(self::KEYWORDS);
// ...
}
run initializes $input and output, then validates the input and calls execute($input, $output) later.
Upvotes: 7