Command not working?

Hii there,

I;m trying to build a plugin that allows the use of a Command using Cake\Console\Command class.

For this, I have created a file in src/Command called TranslateCommand.php, containing the following content:

<?php
  namespace FinlayDaG33k\Translate\Command;

  use Cake\Console\Arguments;
  use Cake\Console\Command;
  use Cake\Console\ConsoleIo;

  class TranslateCommand extends Command {
    public function execute(Arguments $args, ConsoleIo $io) {
      $io->out('Translate command ran');
    }
  }

I’ve also added the following line in my src/Application.php (of the main app):

$this->addPlugin('FinlayDaG33k/Translate');

But when I run cake --help it’s not in the list nor when I call cake translate, I get a “command not found” error (from the cake cli).
My question hereby is, how do I call the console commands created by a plugin?

Good day, I just had the same issue with my project.
I think it is probably caused by the src/Plugin.php file generated by an older version of bake. The console method does not call its parent and should or should be removed. Check my answer on stack overflow for more details.

Stack OverFlow Answer

1 Like

Ye, that seems about right…
Sorry, I haven’t updated the fact that I solved this issue a while ago, but tl;dr, it was the same fix.

See my code here:

Unfortunately, I have stopped working on said plugin because I ran into some issues with the Google API I tried to (ab)use : >
Still looking into getting it to work with a legitimate API key but for that, I’d need to get a free API key first.