1

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

2 Answers 2

1

Your Argument Names are wrong, they should not be with space. for your case you have used

const INPUT_KEY_REFERENCE = 'Amount has been credited';

it should be like this

const INPUT_KEY_REFERENCE = 'amount_has_been_credited';

ALso in command you need to share the agruments

example:credit:refund ARG1 ARG2

6
  • I updated, still same: Not enough arguments (missing: "credit, amount_has_been_credited").
    – Ajwad Syed
    Commented Jun 26, 2019 at 9:48
  • Can you please share the command you are trying Commented Jun 26, 2019 at 10:27
  • example:credit:refund
    – Ajwad Syed
    Commented Jun 26, 2019 at 10:57
  • 1
    Sorry to ask but where are the arguments in this command it should be like example:credit:refund ARG1 ARG2 Commented Jun 26, 2019 at 11:11
  • Yes it worked, can you update answer so that I can accept.
    – Ajwad Syed
    Commented Jun 26, 2019 at 11:33
0

In your configure() function add your argument AMOUNT for amount :

->addArgument(self:: INPUT_KEY_AMOUNT,InputArgument::REQUIRED,'Action Amount');
1
  • Yes it is added..I missed it while pasting code here.. including this code these errors use to occur
    – Ajwad Syed
    Commented Jun 26, 2019 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.