Search code examples
symfonyconsolesymfony-console

Is it possible to move the console "Command" folder from it's default directory and avoiding the Exception: Command "name" is not defined?


By default the console command folder is in: MyProject\MyBundle\Command and all works as expected, but if I move the folder in another directory like :MyProject\MyBundle\MyFolder\Command on command execution it thrown an: [InvalidArgumentException] Command "command_name" is not defined.

I haven't been able to find anything useful after searching over the internet and reading all the documentation possibly related to this problem...

The question is: Exist a mode to move that folder or I'll be forced to use the default folder?

Thanks!


Solution

  • You can define it as a service:

    my_command:
        class: MyProject\MyBundle\MyFolder\Command\MyCommand
        tags:
            -  { name: console.command }
    

    You can read more about this method in Symfony documentation.