<p dir="auto"><strong>Symfony version(s) affected</strong>: 3.4</p>
<p dir="auto"><strong>Description</strong></p>

<p dir="auto"><a href="https://symfony.com/doc/current/console/calling_commands.html" rel="nofollow">Calling a command</a> that has a required argument from another command works fine normally, but when called from a command being run as the default command, an error such as 'Cannot add a required argument after an optional one' will be thrown.</p>
<p dir="auto">It may have something to do with the way the <code class="notranslate">$definition</code> is built in <code class="notranslate">Application</code> when <code class="notranslate">$name</code> is falsey, then <code class="notranslate">Command::mergeApplicationDefinition()</code> is called on <code class="notranslate">Command::run()</code>, but I'm not really sure.</p>
<p dir="auto"><a href="https://github.com/symfony/symfony/issues/25632" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/25632/hovercard">Possibly related issue</a></p>
<p dir="auto"><strong>How to reproduce</strong><br>
Create app.php</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
require(__DIR__ . '/vendor/autoload.php');

class DefaultCommand extends Command{
	static public $defaultName = 'default';
	protected function execute(InputInterface $input, OutputInterface $output){
		$output-&gt;writeln('DefaultCommand');
		$command = $this-&gt;getApplication()-&gt;find('other');
		$command-&gt;run(new ArrayInput([
			'command'=&gt; 'other'
			,'arg'=&gt; 'a'
		]), $output);
	}
}
class OtherCommand extends Command{
	static public $defaultName = 'other';
	protected function configure(){
		$this-&gt;addArgument('arg', InputArgument::REQUIRED);
	}
	protected function execute(InputInterface $input, OutputInterface $output){
		$output-&gt;writeln('OtherCommand ' . $input-&gt;getArgument('arg'));
	}
}

echo &quot;----------\nRunning `&quot; . implode(' ', $_SERVER['argv']) . &quot;`\n&quot;;
$app = new Application();
$app-&gt;add(new DefaultCommand());
$app-&gt;add(new OtherCommand());
$app-&gt;setDefaultCommand('default');
$app-&gt;run();"><pre class="notranslate"><span class="pl-ent">&lt;?php</span>
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Console</span>\<span class="pl-v">Application</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Console</span>\<span class="pl-v">Command</span>\<span class="pl-v">Command</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Console</span>\<span class="pl-v">Input</span>\<span class="pl-v">ArrayInput</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Console</span>\<span class="pl-v">Input</span>\<span class="pl-v">InputArgument</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Console</span>\<span class="pl-v">Input</span>\<span class="pl-v">InputInterface</span>;
<span class="pl-k">use</span> <span class="pl-v">Symfony</span>\<span class="pl-v">Component</span>\<span class="pl-v">Console</span>\<span class="pl-v">Output</span>\<span class="pl-v">OutputInterface</span>;
<span class="pl-k">require</span>(__DIR__ . <span class="pl-s">'/vendor/autoload.php'</span>);

<span class="pl-k">class</span> <span class="pl-v">DefaultCommand</span> <span class="pl-k">extends</span> <span class="pl-v">Command</span>{
	<span class="pl-k">static</span> <span class="pl-k">public</span> <span class="pl-c1"><span class="pl-c1">$</span>defaultName</span> = <span class="pl-s">'default'</span>;
	<span class="pl-k">protected</span> <span class="pl-k">function</span> <span class="pl-en">execute</span>(<span class="pl-smi"><span class="pl-smi">InputInterface</span></span> <span class="pl-s1"><span class="pl-c1">$</span>input</span>, <span class="pl-smi"><span class="pl-smi">OutputInterface</span></span> <span class="pl-s1"><span class="pl-c1">$</span>output</span>){
		<span class="pl-s1"><span class="pl-c1">$</span>output</span>-&gt;<span class="pl-en">writeln</span>(<span class="pl-s">'DefaultCommand'</span>);
		<span class="pl-s1"><span class="pl-c1">$</span>command</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">getApplication</span>()-&gt;<span class="pl-en">find</span>(<span class="pl-s">'other'</span>);
		<span class="pl-s1"><span class="pl-c1">$</span>command</span>-&gt;<span class="pl-en">run</span>(<span class="pl-k">new</span> <span class="pl-v">ArrayInput</span>([
			<span class="pl-s">'command'</span>=&gt; <span class="pl-s">'other'</span>
			,<span class="pl-s">'arg'</span>=&gt; <span class="pl-s">'a'</span>
		]), <span class="pl-s1"><span class="pl-c1">$</span>output</span>);
	}
}
<span class="pl-k">class</span> <span class="pl-v">OtherCommand</span> <span class="pl-k">extends</span> <span class="pl-v">Command</span>{
	<span class="pl-k">static</span> <span class="pl-k">public</span> <span class="pl-c1"><span class="pl-c1">$</span>defaultName</span> = <span class="pl-s">'other'</span>;
	<span class="pl-k">protected</span> <span class="pl-k">function</span> <span class="pl-en">configure</span>(){
		<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">addArgument</span>(<span class="pl-s">'arg'</span>, <span class="pl-v">InputArgument</span>::<span class="pl-c1">REQUIRED</span>);
	}
	<span class="pl-k">protected</span> <span class="pl-k">function</span> <span class="pl-en">execute</span>(<span class="pl-smi"><span class="pl-smi">InputInterface</span></span> <span class="pl-s1"><span class="pl-c1">$</span>input</span>, <span class="pl-smi"><span class="pl-smi">OutputInterface</span></span> <span class="pl-s1"><span class="pl-c1">$</span>output</span>){
		<span class="pl-s1"><span class="pl-c1">$</span>output</span>-&gt;<span class="pl-en">writeln</span>(<span class="pl-s">'OtherCommand '</span> . <span class="pl-s1"><span class="pl-c1">$</span>input</span>-&gt;<span class="pl-en">getArgument</span>(<span class="pl-s">'arg'</span>));
	}
}

<span class="pl-k">echo</span> "<span class="pl-s">----------</span>\n<span class="pl-s">Running `</span>" . implode(<span class="pl-s">' '</span>, <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-c1">_SERVER</span></span>[<span class="pl-s">'argv'</span>]) . "<span class="pl-s">`</span>\n";
<span class="pl-s1"><span class="pl-c1">$</span>app</span> = <span class="pl-k">new</span> <span class="pl-v">Application</span>();
<span class="pl-s1"><span class="pl-c1">$</span>app</span>-&gt;<span class="pl-en">add</span>(<span class="pl-k">new</span> <span class="pl-v">DefaultCommand</span>());
<span class="pl-s1"><span class="pl-c1">$</span>app</span>-&gt;<span class="pl-en">add</span>(<span class="pl-k">new</span> <span class="pl-v">OtherCommand</span>());
<span class="pl-s1"><span class="pl-c1">$</span>app</span>-&gt;<span class="pl-en">setDefaultCommand</span>(<span class="pl-s">'default'</span>);
<span class="pl-s1"><span class="pl-c1">$</span>app</span>-&gt;<span class="pl-en">run</span>();</pre></div>
<p dir="auto">Run in bash-like shell:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="composer require symfony/console
php app.php default; php app.php"><pre class="notranslate">composer require symfony/console
php app.php default<span class="pl-k">;</span> php app.php</pre></div>
<p dir="auto">output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="----------
Running `app.php default`
DefaultCommand
OtherCommand a
----------
Running `app.php`
DefaultCommand


  Cannot add a required argument after an optional one.


default"><pre class="notranslate"><code class="notranslate">----------
Running `app.php default`
DefaultCommand
OtherCommand a
----------
Running `app.php`
DefaultCommand


  Cannot add a required argument after an optional one.


default
</code></pre></div>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>4.0.2</td>
</tr>
</tbody>
</table>
<p dir="auto">Hi,</p>
<p dir="auto">Consider moving dotenv dependency from require-dev to require by default.</p>
<p dir="auto">Yes, I read docs about .env for development and setting environmental parameters on system.</p>
<p dir="auto">But I don't think what there is some profit in it at all. I don't use Apache mod-php and docker. I want to be able to configure multiple application on one host easily.</p>