Browse Source

Merge pull request #13194 from cakephp/4.x-console-addSubcommand

4.x - throw RuntimeException when using subcommands in console
Mark Story 7 years ago
parent
commit
cc12b275c6
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/Console/Command.php

+ 9 - 1
src/Console/Command.php

@@ -22,6 +22,7 @@ use Cake\Datasource\ModelAwareTrait;
 use Cake\Log\LogTrait;
 use Cake\ORM\Locator\LocatorAwareTrait;
 use InvalidArgumentException;
+use RuntimeException;
 
 /**
  * Base class for console commands.
@@ -117,7 +118,14 @@ class Command
         $parser = new ConsoleOptionParser($name);
         $parser->setRootName($root);
 
-        return $this->buildOptionParser($parser);
+        $parser = $this->buildOptionParser($parser);
+        if ($parser->subcommands()) {
+            throw new RuntimeException(
+                'You cannot add sub-commands to `Command` sub-classes. Instead make a separate command.'
+            );
+        }
+
+        return $parser;
     }
 
     /**