argparse: How to make mutually exclusive arguments optional?
<p>I want to use my script like this:</p>

<pre><code>python test.py run
python test.py stop
</code></pre>

<p>and my code is like this:</p>

<pre><code>parser = argparse.ArgumentParser()
command_group = parser.add_mutually_exclusive_group(required=True)
command_group.add_argument('run', help='run it', action='store_true')
command_group.add_argument('stop', help='stop it', action='store_true')
</code></pre>

<p>when I execute it, an exception is raised:</p>

<pre><code>ValueError: mutually exclusive arguments must be optional
</code></pre>

<p>so I try to add <code>required=False</code> when I add each argument.Then I get another exception:</p>

<pre><code>TypeError: 'required' is an invalid argument for positionals
</code></pre>

<p>I'm confused. </p>