title: How to accept positional argument in main parser as well as subparser?
body: <p>I am making a CLI that will accept Fortran code file and some functions in the following manner:-</p>
  <pre class="lang-bash prettyprint-override"><code>prog -m module_name example.f only: add sub
  </code></pre>
  <p>How can I accept values after <code>only:</code> as separate positional arguments?</p>
  <p>Currently <code>argparse</code> is parsing all arguments after <code>module_name</code> as Fortran files. My code is as follows.</p>
  <pre><code>parser = argparse.ArgumentParser(prog=&quot;prog&quot;, help = &quot;Help text)
  
  parser.add_argument(
      &quot;Fortran Files&quot;,
      metavar=&quot;&lt;fortran files&gt;&quot;,
      action=&quot;extend&quot;,  # List storage
      nargs=&quot;*&quot;,
      type=check_fortran,  # Returns a pathlib.Path
      help=&quot;&quot;&quot;Paths to fortranfiles that will be scanned for
                     &lt;fortran functions&gt;.&quot;&quot;&quot;,
  )
  
  parser.add_argument(
      &quot;Keep functions&quot;,
      metavar=&quot;only:&quot;,
      action=&quot;extend&quot;,
      type=str,
      nargs=&quot;*&quot;,
      help=&quot;Use only fortran functions that follow.&quot;,
  )
  
  parser.add_argument(
      &quot;-m&quot;,
      &quot;--module&quot;,
      metavar=&quot;&lt;modulename&gt;&quot;,
      type=str,
      nargs=1,
      help=&quot;&quot;&quot;Name of the module&quot;&quot;&quot;,
  )
  </code></pre>