30
30
use Symfony \Component \Console \Exception \InvalidArgumentException as ConsoleInvalidArgumentException ;
31
31
use Symfony \Component \Console \Input \ArgvInput ;
32
32
use Symfony \Component \Console \Input \ArrayInput ;
33
+ use Symfony \Component \Console \Input \InputDefinition ;
33
34
use Symfony \Component \Console \Input \InputInterface ;
34
35
use Symfony \Component \Console \Input \InputOption ;
35
36
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
@@ -1744,10 +1745,12 @@ protected function getSelectedEnvironment()
1744
1745
/**
1745
1746
* Run another CLI command.
1746
1747
*
1747
- * @param string $name
1748
+ * @param string $name
1748
1749
* The name of the other command.
1749
- * @param array $arguments
1750
+ * @param array $arguments
1750
1751
* Arguments for the other command.
1752
+ * Unambiguous options that both commands have in common will be passed
1753
+ * on automatically.
1751
1754
* @param OutputInterface $output
1752
1755
* The output for the other command. Defaults to the current output.
1753
1756
*
@@ -1760,12 +1763,8 @@ protected function runOtherCommand($name, array $arguments = [], OutputInterface
1760
1763
/** @var Command $command */
1761
1764
$ command = $ application ->find ($ name );
1762
1765
1763
- // Pass on interactivity arguments to the other command.
1764
- if (isset ($ this ->input ) && $ command ->getDefinition ()->hasOption ('yes ' )) {
1765
- $ arguments += [
1766
- '--yes ' => $ this ->input ->getOption ('yes ' ),
1767
- '--no ' => $ this ->input ->getOption ('no ' ),
1768
- ];
1766
+ if (isset ($ this ->input )) {
1767
+ $ this ->forwardStandardOptions ($ arguments , $ this ->input , $ command ->getDefinition ());
1769
1768
}
1770
1769
1771
1770
$ cmdInput = new ArrayInput (['command ' => $ name ] + $ arguments );
@@ -1801,6 +1800,41 @@ protected function runOtherCommand($name, array $arguments = [], OutputInterface
1801
1800
return $ result ;
1802
1801
}
1803
1802
1803
+ /**
1804
+ * Forwards standard (unambiguous) arguments that a source and target command have in common.
1805
+ *
1806
+ * @param array &$args
1807
+ * @param InputInterface $input
1808
+ * @param InputDefinition $targetDef
1809
+ */
1810
+ private function forwardStandardOptions (array &$ args , InputInterface $ input , InputDefinition $ targetDef )
1811
+ {
1812
+ $ stdOptions = [
1813
+ 'no ' ,
1814
+ 'no-interaction ' ,
1815
+ 'yes ' ,
1816
+
1817
+ 'no-wait ' ,
1818
+ 'wait ' ,
1819
+
1820
+ 'org ' ,
1821
+ 'host ' ,
1822
+ 'project ' ,
1823
+ 'environment ' ,
1824
+ 'app ' ,
1825
+ 'worker ' ,
1826
+ 'instance ' ,
1827
+ ];
1828
+ foreach ($ stdOptions as $ name ) {
1829
+ if (!\array_key_exists ('-- ' . $ name , $ args ) && $ targetDef ->hasOption ($ name ) && $ input ->hasOption ($ name )) {
1830
+ $ value = $ input ->getOption ($ name );
1831
+ if ($ value !== null ) {
1832
+ $ args ['-- ' . $ name ] = $ value ;
1833
+ }
1834
+ }
1835
+ }
1836
+ }
1837
+
1804
1838
/**
1805
1839
* Add aliases that should be hidden from help.
1806
1840
*
0 commit comments