I am creating console command to input values into the database, there is some argument missing an error. I have gone through several tutorials but to me, the code looks fine. The error is:
Not enough arguments (missing: "Credit, Amount has been credited").
Here is Console Class:
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Vendor\Module\Model\AmountFactory;
class AddItem extends Command
{
const INPUT_KEY_ACTION = 'Credit';
const INPUT_KEY_REFERENCE = 'Amount has been credited';
//const INPUT_KEY_AMOUNT = 50;
private $amountFactory;
public function __construct(AmountFactory $amountFactory)
{
$this->amountFactory = $amountFactory;
parent::__construct();
}
protected function configure()
{
$this->setName('example:credit:refund')
->addArgument(
self::INPUT_KEY_ACTION,
InputArgument::REQUIRED,
'Action name'
)->addArgument(
self::INPUT_KEY_REFERENCE,
InputArgument::REQUIRED,
'Action Reference'
);
//$this->setDescription('Demo console command');
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$amount = $this->amountFactory->create();
$amount->setAction($input->getArgument(self::INPUT_KEY_ACTION));
$amount->setReference($input->getArgument(self::INPUT_KEY_REFERENCE));
//$amount->setAmount($input->getArgument(self::INPUT_KEY_AMOUNT));
$amount->setIsObjectNew(true);
$amount->save();
return Cli::RETURN_SUCCESS;
}
}
In di.xml:
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="rhinosCredit" xsi:type="object">Vendor\Module\Console\Command\AddItem</item>
</argument>
</arguments>
When I uncomment lines for third argument i.e Amount I get error
The "50" argument does not exist.
Can somebody help to figure out this error? Thank you