Magento 2.1 – Cannot Add New CLI Command on setup:upgrade

commandmagento-2.1module

I am trying add custom command for beginning 'hello world'. I'm doing all by guide but always have this error

[ReflectionException]
Class Hesoy\HelloWorld\Console\Command\HelloWorldCommand does not exist

This is my setup steps:

  1. Clear cache
  2. setup:upgrade

This is my files

Command

namespace Hesoy\HelloWorld\Console\Command;


use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class HelloWorldCommand extends Command
{
    public function __construct($name = null)
    {
        parent::__construct($name);
    }

    protected function configure()
    {
        $this->setName('hesoy:hello-world')
            ->setDescription('Hello world');

        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Hello world!');
    }
}

di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\Console\CommandListInterface">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="helloWorld" xsi:type="object">Hesoy\HelloWorld\Console\Command\HelloWorldCommand</item>
            </argument>
        </arguments>
    </type>
</config>

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Hesoy_HelloWorld" setup_version="0.1.0">
    </module>
</config

registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Hesoy_HelloWorld',
    __DIR__
);

Best Answer

Invalid di.xml. Please correct it.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\Console\CommandListInterface">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="helloWorld" xsi:type="object">Hesoy\HelloWorld\Console\Command\HelloWorldCommand</item>
            </argument>
        </arguments>
    </type>
</config>